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 2000 Forums
 Transact-SQL (2000)
 how to randomly select cetain number to run

Author  Topic 

ntn104
Posting Yak Master

175 Posts

Posted - 2011-10-13 : 13:40:17
How can I select 1000 accounts from table randomly....

thanks,

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-10-13 : 13:45:36
[code]select top 1000 * from yourtable order by newid() [/code]

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

Go to Top of Page

ntn104
Posting Yak Master

175 Posts

Posted - 2011-10-13 : 13:49:15
I want to get randomly selected accounts, not top value....how should I do it...thanks,

quote:
Originally posted by visakh16

select top 1000 * from yourtable order by newid() 


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



Go to Top of Page

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2011-10-13 : 13:51:21
Do as Visakh suggested and see that it works. You will get a different 1000 rows every time.



Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

ntn104
Posting Yak Master

175 Posts

Posted - 2011-10-13 : 13:57:53
It does not work...show all the 1000 records that had higher value of income....thanks,

quote:
Originally posted by ntn104

I want to get randomly selected accounts, not top value....how should I do it...thanks,

quote:
Originally posted by visakh16

select top 1000 * from yourtable order by newid() 


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





Go to Top of Page

ntn104
Posting Yak Master

175 Posts

Posted - 2011-10-13 : 14:00:10
I am sorry visakh16, it works with your suggestion....I forget to put order by id....so that was why I got all higher value of income at first...

thanks much!
quote:
Originally posted by ntn104

I want to get randomly selected accounts, not top value....how should I do it...thanks,

quote:
Originally posted by visakh16

select top 1000 * from yourtable order by newid() 


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






[/quote]
Go to Top of Page
   

- Advertisement -