Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Create random number
Message
 
 
To
03/06/2012 10:26:10
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:
01545184
Views:
52
>>Hi,
>>
>>In VFP I am creating a random number (that has to fit into N(8,0) size field) as following:
>>
>>
>>rand(-1)
>>nNumber = int( rand() * 100000000 )
>>
>>
>>I found online article that has the following code for creating a random number:
>>
>>
>>SELECT CAST(RAND() * 1000000 AS INT) AS [RandomNumber]
>>
>>
>>Is this equivalent to the VFP code?
>
>Unless you are running a lottery or something, I see no reason why you would want a random number. Generating of any random number implies the new number might already exist in the table.
>
>I also think it really unfortunate that you started by asking for a random number, and no one stops you to ask what do you intend to do with it. That resulted in a lot of noise that served no purpose.
>
>You seem to be requiring a number that is unique to each record. If not, please explain what you are doing.

Yes, I do need a unique number to be set into a field of a table (not PK field). In VFP I have used the random number approach for this case and have not had any problems. Why could not the same work in SQL?
"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
Next
Reply
Map
View

Click here to load this message in the networking platform