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
 General SQL Server Forums
 New to SQL Server Programming
 Random Record selection

Author  Topic 

jcb267
Constraint Violating Yak Guru

291 Posts

Posted - 2012-08-01 : 12:00:26
Hi -

I have a table with 471 records. I would like to select 30 from that table randomly. Will this do that?

select top 30 siteid into randomsites from tempsites order by newid()

If not, how can I accomplish a random selection?

Thanks!!

JB

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-08-01 : 12:03:08
yep...the given statement should do that



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

Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2012-08-01 : 12:03:58
yeah -- that's about the best you can do to get a random selection

Transact Charlie
Msg 3903.. The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION.
http://nosqlsolution.blogspot.co.uk/
Go to Top of Page

jcb267
Constraint Violating Yak Guru

291 Posts

Posted - 2012-08-01 : 12:12:21
Excellant! Thankyou Vikash and Transact Charlie!!

JB
Go to Top of Page
   

- Advertisement -