Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Create random number
Message
From
03/06/2012 12:16:46
 
General information
Forum:
Microsoft SQL Server
Category:
Other
Environment versions
SQL Server:
SQL Server 2005
Miscellaneous
Thread ID:
01545107
Message ID:
01545186
Views:
49
>>Sort of. Do you want to create a random number for every row or a single value? RAND() function will return the same value for all rows in the result, so you need to use checksum(NewID()) in order to generate random value for every row.
>>
>>Check this article by Pinal Dave
>>http://blog.sqlauthority.com/2007/04/29/sql-server-random-number-generator-script-sql-query/
>
>I want/need to create just one random number for the current row, when Inserting a record. This is not a PK field but still, for business purpose, needs to have a unique entry. So I don't think that I would need to use checksum().

Uuhm,

unique entry negates "true" randomness
even for pseudo random distributions like the machine generated ones...

If you need it for sampling or statistical work,
allow duplicate numbers and work via set instead of creating a unique value.

regards

thomas
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform