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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Register Now and get your question answered!
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Generating Random Numbers on Every Row with RAND()
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Yak Posting Veteran

55 Posts

Posted - 05/01/2013 :  17:26:16  Show Profile  Reply with Quote
I am using the RAND() function. I am multiplying by 20 to get a larger number since RAND returns numbers between 0 and 1.

The problem is that RAND generates only 1 random number and copies that down each row. But I want a different randome number on each row.

I am using the AdventureWorks2012 database on SQL Server Express on my laptop.

ProductID int IDENTITY (1,1),
Price money NOT NULL,
Qty int NULL


SELECT ListPrice, RAND()*20
FROM Production.Product

FROM @Drago

Flowing Fount of Yak Knowledge

4614 Posts

Posted - 05/01/2013 :  17:43:10  Show Profile  Reply with Quote
Don't use the RAND function. Try using the NEWID function.
Go to Top of Page

Very Important crosS Applying yaK Herder

52326 Posts

Posted - 05/02/2013 :  04:36:10  Show Profile  Reply with Quote

SQL Server MVP
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000