How can I get random numbers from SQL Server? Using rand() I always get the same sequence.

Neil Pike

April 18, 1999

1 Min Read
ITPro Today logo in a gray background | ITPro Today

A. A. This is because you need to start the rand function off with arandom number. Use something like :-

SELECT RAND( (DATEPART(mm, GETDATE()) * 100000 )
+ (DATEPART(ss, GETDATE()) * 1000 )
+ DATEPART(ms, GETDATE()) )

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like