Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Create random number
Message
 
 
To
04/06/2012 10:41:17
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:
01545226
Views:
62
Likes (1)
>>>>>>>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
>>
>>As I mentioned, having the number generated as random perfectly serves my purpose. All I wanted (if you read my initial question) is to know that what the expression (I found online) of generating of a random number in a SQL server stored procedure will do the same as what I was using in VFP. Naomi confirmed that. And I already tested this expression and it works. So I don't see any more need to beat this dead horse.
>>Thanks.
>
>I watch you and Naomi discuss many things. Neither of you seem to have a firm grasp of certain fundamentals, or you would not have beaten this horse to death already.
>
>Good luck with keeping the blinders on.

I very much trust Naomi's technical knowledge and input. I do not want to comment on your technical knowledge but you obviously (I am not the first to notice it) lack of tact and humility. It looks like you are angry about something all the time. Keep in mind that having this anger and if you carry and extra 20-30 lbs of weight, your blood pressure can increase dramatically and cause serious health problems.
Take care.
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Previous
Reply
Map
View

Click here to load this message in the networking platform