我正在使用低于标准的游标,但是如我所述给予错误。任何帮助将不胜感激。提前致谢 [英] I AM USING BELOW CURSOR BUT GIVING ME ERROR AS STATED. ANY HELP WILL BE GREATLY APPRECIATED. THANKS IN ADVANCE

查看:77
本文介绍了我正在使用低于标准的游标,但是如我所述给予错误。任何帮助将不胜感激。提前致谢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

DECLARE @sql VARCHAR (MAX)
DECLARE @mid AS BIGINT
DECLARE @cursor AS CURSOR

SET @SQL =

SELECT [MERCHANT_ID] from [Reports].[MONAD\karal.ramil].[REF#19414MHTNEEDED]


OPEN @cursor

FETCH @cursor INTO @mid
WHILE @@FETCH_STATUS = 0
BEGIN
PRINT @mid
SELECT MERCHANT_NUMBER
INTO #TEMP
FROM [BI].[dbo].[MERCHANT_PROFILE]
WHERE YEAR_MONTH =201503 AND THIS_MHT_TYPE ='MRCH' AND MERCHANT_NUMBER LIKE '%' + @mid
FETCH NEXT
FROM @cursor INTO @mid
END
CLOSE @cursor
DEALLOCATE @cursor



--error -------

消息16950,级别16,状态2,行35

变量'@cursor'当前没有分配光标。

消息16950,Level 16,State 2,Line 40

变量'@cursor'目前没有分配光标。

消息16950,等级16,状态2 ,第52行

变量'@cursor'目前没有分配光标。

消息16950,等级16,状态2,行53

变量'@cursor'当前没有分配游标。


--error-------
Msg 16950, Level 16, State 2, Line 35
The variable '@cursor' does not currently have a cursor allocated to it.
Msg 16950, Level 16, State 2, Line 40
The variable '@cursor' does not currently have a cursor allocated to it.
Msg 16950, Level 16, State 2, Line 52
The variable '@cursor' does not currently have a cursor allocated to it.
Msg 16950, Level 16, State 2, Line 53
The variable '@cursor' does not currently have a cursor allocated to it.

推荐答案

1。请不要喊。不要使用所有CAPS。

2.请参阅 https:// msdn。 microsoft.com/en-us/library/ms180169.aspx [ ^ ]。声明游标时需要使用FOR SELECT语句。你缺少select_statement。

3.我不确定它是否有所作为;但是,当我完成游标时,我不在游标名称上使用@。
1. Please do not shout. Do not use all CAPS.
2. See, https://msdn.microsoft.com/en-us/library/ms180169.aspx[^]. You need to use a FOR SELECT statement when you declare the cursor. You are missing select_statement.
3. I'm not sure if it makes a difference; however, when I have done cursors I don't use @ on the cursor name.


这篇关于我正在使用低于标准的游标,但是如我所述给予错误。任何帮助将不胜感激。提前致谢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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