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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

*** Returning a Set Number of Random Records ***

Status
Not open for further replies.

jonnywah

Programmer
Feb 7, 2004
80
US
I have the following code where @chemicalTypeId is a parameter in my stored procedure GetRandomChemicals:

select * from chemicals
where chemicalTypeId1 = @chemicalTypeId
or chemicalTypeId2 = @chemicalTypeId
or chemicalTypeId3 = @chemicalTypeId
or chemicalTypeId4 = @chemicalTypeId

GetRandomChemicals should return up to 6 chemicals with a chemicalTypeId (1 to 4) that is equal to @chemicalTypeId.

GetRandomChemicals can return from 0 records to hundreds of records. However I want to randomly return up to a maximum of 6 records / chemicals each time the stored procedure is called.

How can I do this?? Please help. Any suggestions or information would be appreciated. Thank you in advance.



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top