Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Rand function
Message
 
 
To
07/05/2002 16:42:25
Dave Sonier
Technologies Nter inc.
Gatineau, Quebec, Canada
General information
Forum:
Microsoft SQL Server
Category:
Stored procedures, Triggers, UDFs
Title:
Miscellaneous
Thread ID:
00653746
Message ID:
00653794
Views:
19
>Hi,
>
>How can I a random number between 1 to 150 ??? I tried the RAND function but i got a number between 0 to 1 like 0,0077343343...
>
DECLARE @RandMin Int, @RandMax int
SET @RandMin = 1
SET @RandMax =150
SELECT CAST((@RandMax - @RandMin) * @Rand + @RandMin AS int)
If you've Sql Server 2000 you can convert above code into UDF. To start the rand function off with a random number use something like
SELECT RAND( (DATEPART(mm, GETDATE()) * 100000 ) +
   (DATEPART(ss, GETDATE()) * 1000 ) +
    DATEPART(ms, GETDATE()) )
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform