游标声明中不允许使用变量赋值 [英] variable assignment is not allowed in a cursor declaration

查看:781
本文介绍了游标声明中不允许使用变量赋值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

设置ANSI_NULLS开启

设置QUOTED_IDENTIFIER ON

GO



ALTER proc [dbo]。[OH_Bulkbooking_Course ](@ AllStud_id varchar(max),@ BatchID varchar(20),@ UserID varchar(30))

as

begin



声明@Stud_id varchar(20),@ status varchar(max),@ tempitems varchar(max)



create table #Temptable(Stud_id varchar(max),status varchar(max),tempitems varchar(max))



声明studcur游标为



从Fnsplit中选择@tempitems =项目(@AllStud_id,',')

打开studcur

从studcur下一步获取到@Stud_id



WHILE @@ fetch_status = 0

开始



设置@status = OH_Course_Reg(@ tempitems,@ BatchID,@ UserID)

插入Temptable值(@ tempitems,@ status)



从studcur下一步获取到@Stud_id

结束



close studcur

deallocate studcur



select * from #Temptable

end





当我执行上面的存储过程时显示错误如下



游标声明中不允许变量赋值



以上错误显示如下以下

从Fnsplit中选择@tempitems =项目(@AllStud_id,',')



请帮帮我。我怎样才能解决这个问题。



问候,

Narasiman P

解决方案

< blockquote>错误在这一行下面:

插入 Temptable 值(@ tempitems,@ status)



替换它:

插入 #Temptable 值(@ tempitems,@ status)





最好的问候,





莱昂纳多计

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO

ALTER proc [dbo].[OH_Bulkbooking_Course](@AllStud_id varchar(max),@BatchID varchar(20),@UserID varchar(30))
as
begin

declare @Stud_id varchar(20),@status varchar(max),@tempitems varchar(max)

create table #Temptable (Stud_id varchar(max),status varchar(max),tempitems varchar(max))

declare studcur cursor for

select @tempitems = items from Fnsplit(@AllStud_id,',')
open studcur
fetch next from studcur into @Stud_id

WHILE @@fetch_status = 0
begin

set @status = OH_Course_Reg(@tempitems,@BatchID,@UserID)
insert into Temptable values(@tempitems,@status)

fetch next from studcur into @Stud_id
end

close studcur
deallocate studcur

select * from #Temptable
end


When i execute the above store procedure shows error as follows

variable assignment is not allowed in a cursor declaration

The above error shows in below line as follows
select @tempitems = items from Fnsplit(@AllStud_id,',')

please help me. how can i solve the problem.

Regards,
Narasiman P

解决方案

the error is on this line bellow:
insert into Temptable values(@tempitems,@status)

replace it for this:
insert into #Temptable values(@tempitems,@status)


Best Regards,


Leonardo Metre


这篇关于游标声明中不允许使用变量赋值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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