Click here to Skip to main content
15,914,500 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi every one,

I have a Stored Procedure that contains two queries, those returns multiple rows when executed.The 2st query depends on the output of 1st query.So i want to store the result of 1st query(that contains multiple rows)in procedure itself and use it in 2nd query.Is there any thing in stored procedure to store the result like "DataSet" in frontend?

If yes please tell me about it or guide me how to do this.

Thanks....
Posted

1 solution

You can nest queries:
SELECT TOP 5 * FROM [myDatabase].[dbo].[Customers] WHERE ID IN 
  (
   SELECT ID FROM [myDatabase].[dbo].[Customers] WHERE ID > 5 
   EXCEPT
   SELECT iD FROM [myDatabase].[dbo].[Customers] WHERE ID < 10
  )
Or create temporary tables: SQL – Temporary Tables[^] or MSDN[^]
 
Share this answer
 
Comments
Herman<T>.Instance 19-Jul-11 9:45am    
it is advised to use a temporary table (don't foret to drop at the end of the stored procedure) because nesting (subselecting) can be very costly and result in bad performance

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