Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I want create a function in stored procedure. If i have a table in which there are more than one rows which have similar name but different categories, now i want create a random function after that onr row will select automatically.
Posted

Hi try this,

SQL
Select * from tablename order by newid()

this will retrieve the rows randomnly...
 
Share this answer
 
v3
Comments
member60 18-Jun-12 4:35am    
My 5!
To select a random record, combine TOP with NEWID:
SQL
SELECT TOP 1 * from MyTable ORDER BY NEWID()
In your case, you will probably need to replace MyTable with your procedure output.
 
Share this answer
 
Comments
Maciej Los 18-Jun-12 4:24am    
Good answer, my 5!
member60 18-Jun-12 4:35am    
my 5!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900