将crsor设置为存储过程sql2008 [英] setting crsor to a stored procedure sql2008

查看:79
本文介绍了将crsor设置为存储过程sql2008的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我想将游标设置为执行我的select语句的存储过程,而不是直接将其设置为select语句,该怎么办?
我只希望有一个游标,并根据某些条件将其设置为不同的存储过程,有两种方法可以做到这一点,如我在下面给出的,但是第一种方法不起作用,第二种方法可以,我想这样做第一种方法,它允许我声明可以设置为不同选择语句的单个游标,但是当涉及到存储过程时,这种声明不起作用,并且sql浏览器会引发错误.谁能帮助我该怎么做?

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




在此先感谢,
问候
Ravikiran




Thanks in Advance,
Regards
Ravikiran

推荐答案

我不确定您真正想要实现什么,但是由于您使用的是SQL2008,因此您是否检查过使用CTE是否比使用游标更好?

MSDN CTE [
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[^]


这篇关于将crsor设置为存储过程sql2008的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆