All Forums Database
nihal_045 4 posts Joined 12/13
04 Jan 2015
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
 
 

- Nihal
dnoeth 4628 posts Joined 11/04
05 Jan 2015

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;

 

Dieter

You must sign in to leave a comment.