Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Create random number
Message
From
03/06/2012 17:56:19
Mike Yearwood
Toronto, Ontario, Canada
 
General information
Forum:
Microsoft SQL Server
Category:
Other
Environment versions
SQL Server:
SQL Server 2005
Miscellaneous
Thread ID:
01545107
Message ID:
01545195
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
>
>Ok. I see. I take it back. I don't need a unique entry in the field. I just want a random number of so many digits (as pretty much the title of the thread said).

Would you please stop listening to and being confused by the various bits of advice you are getting here? Please explain in English (without referring to what you think the solution might be) exactly what you are trying to accomplish.

I think you want a number which is not duplicated within the set of records. So, let's pretend this is an invoice. Do you want every invoice to have a unique number?

1,2,3,4,5

or do you think there is some benefit to having every invoice number be random

23534635454, 45645734324, 456322354353, 342342, 13?

I would like you to explain how the second example is any benefit.

Thanks
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform