Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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?
 
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 12-Jul-11 19:40pm
Roliking1.1K

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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[^]
  Permalink  

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

  Print Answers RSS
0 Peter Leow 375
1 Sergey Alexandrovich Kryukov 270
2 Zoltán Zörgő 258
3 CHill60 195
4 TheRealSteveJudge 180
0 Sergey Alexandrovich Kryukov 8,853
1 OriginalGriff 6,631
2 Peter Leow 4,102
3 Zoltán Zörgő 3,714
4 Kornfeld Eliyahu Peter 2,525


Advertise | Privacy | Mobile
Web04 | 2.8.150123.1 | Last Updated 13 Jul 2011
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100