Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello All,

I want to set a cursor to a stored procedure which executes my select statement instead of directly setting it to a select statement, how can i do this?
I want to have only one cursor and set it to different stored procedures depending on some condition, there are two ways to do this as i have given below but the first one does not work and the second one does, i want to do it the first way which allows me to declare a single cursor which can be set to different select statements, but when it comes to stored procedure this kind of declaration is not working and the sql browser throws an error. Can anyone help me how i can do this?

SQL
declare @Cur as cursor
set @cur= CURSOR for  exec sp_Executesql @stmt

declare @cursor cursor exec sp_Executesql @stmt



Thanks in Advance,
Regards
Ravikiran
Posted

1 solution

I am not sure what you actually want to achieve, but since you are using SQL2008 have you checked whether using a CTE is a better approach than a cursor?

MSDN CTE[^]
 
Share this answer
 

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