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

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 OriginalGriff 390
1 Jochen Arndt 165
2 Richard MacCutchan 135
3 DamithSL 95
4 Garth J Lancaster 90
0 OriginalGriff 6,045
1 DamithSL 4,601
2 Maciej Los 4,032
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,220


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 13 Jul 2011
Copyright © CodeProject, 1999-2014
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