Click here to Skip to main content
11,644,982 members (61,781 online)
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 18:40pm
Roliking1.2K

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 725
1 jyo.net 494
2 Sergey Alexandrovich Kryukov 464
3 Afzaal Ahmad Zeeshan 404
4 CPallini 386
0 OriginalGriff 1,020
1 Sergey Alexandrovich Kryukov 673
2 DamithSL 656
3 Afzaal Ahmad Zeeshan 652
4 CPallini 555


Advertise | Privacy | Mobile
Web01 | 2.8.150731.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