Tech Support Guy banner
Status
Not open for further replies.
1 - 4 of 4 Posts

·
Registered
Joined
·
451 Posts
Discussion Starter · #1 ·
Hi,

I need to perform the following query:

'update table table_name set field_name=cast(int, rand()*100+1)'

The problem is that rand() returns the same 'random' number for all fields.
Is there any way to generate efficient random numbers - and a different one for each entry to be updated?

D.
 

·
Registered
Joined
·
591 Posts
it sounds like you may be calling the rand function only once and updating all the fields with the returned number.
you can try a couple of things..
1. create variables for each of the fields you want to update, define each as a separate rand function call, and update the row using the variables.
2. repeat the update statement for each field separately?

which database are you using?
 

·
Registered
Joined
·
21,875 Posts
What is the random number it is generating each time? I was under the impression that you needed a range of numbers to use as the seed for the rnd function. I believe the function ins Rnd, not rand
 

·
Registered
Joined
·
451 Posts
Discussion Starter · #4 ·
ms-sql
(sql server)

There are over half a million entries. I want to avoid having to update each manually.
As to your first suggestion - I am not experience enough in SQL to understand what you mean. Could you please give me a code example?

The basic statement is very simple:

'update table_name set field_name=[a random numeric value]'

Thanks,
D.
 
1 - 4 of 4 Posts
Status
Not open for further replies.
Top