Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Random Numbers

Author  Topic 

Ken Blum
Constraint Violating Yak Guru

383 Posts

Posted - 2010-03-24 : 10:43:33
I have a table that contains records of water temperatures (numeric data type). I need a script that will return a random number between 7 and 12. How can I achieve that?

Select Data_Value, Data_Value + Rand() AS Random_Temp From Water_Temps


TIA,

Ken

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2010-03-24 : 11:25:03
Function F_RANDOM_INTEGER in the script returns a random integer in the range of the input parameters so that the return value is >= @START_INT and <= @END_INT. It is valid for any range of two integer values.

Random Integer, Sample, and Datetime Functions
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=69499

Example:
-- Return random integer between 7, 12
select [Random Integer] = [dbo].[F_RANDOM_INTEGER](7, 12,newid())


CODO ERGO SUM
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-03-24 : 11:33:09
http://sqlblogcasts.com/blogs/madhivanan/archive/2007/10/10/generating-random-numbers-part-ii.aspx

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Ken Blum
Constraint Violating Yak Guru

383 Posts

Posted - 2010-03-24 : 11:41:37
Thanks!
Go to Top of Page
   

- Advertisement -