Random Number Generator based on inputs from column values

Database

Random Number Generator based on inputs from column values

Hi All,

I have used the random(<min_value>,<max_value>) function to generate numbers. However, this only works when the values then numbers are entered manually.

For example

SELECT A.*, RANDOM(1,10) FROM TABLE_NAME A;

works

but 

SELECT A.*, 10 AS TEST, RANDOM(1,TEST) FROM TABLE_NAME A;

doesn't

I get a "Select Failed 3707: Syntax error expected something like an integer or a decimal or a ... between ',' and the word 'TEST' "

Ideally I'd like the inputs to the function to be values from the table itself

Any help on this would be appreciated!

- Nihal

Tags (2)
1 REPLY
Junior Contributor

Re: Random Number Generator based on inputs from column values

Hi Nihal,

RANDOM only accepts hard-coded values.

You might try

SELECT A.*, 10 AS TEST, RANDOM(1,2147483647) MOD TEST + 1 FROM TABLE_NAME A;