Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select Random records from a Table

Status
Not open for further replies.

ramone109

Programmer
Feb 22, 2003
4
US
I have a table that is made up of the following columns:
RecID (primary key)
Name
Address
City
State
Zip
Phone

As an example, I need to pull 5000 records from this table where the state is New York. However, I need to make sure that I don't get the exact same records everytime I run the same query. Any help would be greatly appreciated. Thanks in advance.
 
select top 5000 *
from tbl
order by newid()


======================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top