我的商店程序无效 [英] My store procedure is not working

查看:66
本文介绍了我的商店程序无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了使用逗号分隔值的功能



Fnsplit代码如下

I have created funtion to split the value using comma separted

Fnsplit code as follows

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

ALTER function [dbo].[FnSplit](@String nvarchar(4000), @Delimiter char(1))
Returns @Results Table (Items nvarchar(4000))
As

Begin
Declare @Index int
Declare @Slice nvarchar(4000)
Select @Index = 1
If @String Is NULL Return

While @Index != 0
Begin

Select @Index = CharIndex(@Delimiter, @String)
if(@Index <> 0)
set @Slice = left(@String, @Index - 1)
else
set @Slice = @String
Insert into @Results(Items) Values (@Slice)
Select @String = right(@String, Len(@String) - @Index)
If Len(@String) = 0 break
End
Return
End







然后我创建了一个名为Tb_Coursemessage



select * from Tb_CourseMessage



当我执行上面的表输出如下



留言



课程注册

课程现有

席位不可用





我在该商店程序中创建了一个存储过程我通过上表tb_courseMessage



存储过程如下






Then I created one table called Tb_Coursemessage

select * from Tb_CourseMessage

When I execute the above table output as follows

Message

Course registered
Course exist
seats not available


I created a stored procedure in that store procedure I pass the above table tb_courseMessage

The stored procedure as follows

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

ALTER proc [dbo].[OH_Message]
as
begin
select Cmessage from Tb_CourseMessage
end





当我按如下方式执行上述存储过程输出时



exec [OH_Message]



Cmessage



CourseRegsitered

CourseExist

SeatNotavailable





然后我创建了另一个存储过程如下





When i execute the above stored procedure output as follows

exec [OH_Message]

Cmessage

CourseRegsitered
CourseExist
SeatNotavailable


Then I have created another stored procedure as follows

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)

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

declare studcur cursor for 
select items from Fnsplit(@AllStud_id,',')

 open studcur
 fetch next from studcur into @Stud_id
 
      WHILE @@fetch_status = 0
        begin

     @status =  OH_Message(items,@BatchID,@UserID)

insert into Temptable values(items,@status)

fetch next from studcur into @Stud_id
end

close studcur
deallocate studcur
commit tran 

select * from #Temptable





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



'@status'附近的语法不正确。

在此上下文中不允许使用名称items。有效表达式是常量,常量表达式和(在某些上下文中)变量。不允许使用列名。





来自我上面的存储过程我犯了什么错误请帮帮我



问候,

Narasiman P.



When I execute the above stored procedure show error as follows

Incorrect syntax near '@status'.
The name "items" is not permitted in this context. Valid expressions are constants, constant expressions, and (in some contexts) variables. Column names are not permitted.


from my above stored procedure what is the mistake I made please help me

Regards,
Narasiman P.

推荐答案

尝试使用T-SQL命令 SET 将值分配给@status。



Try using the T-SQL command SET to assign the value to @status.

SET @status =  OH_Message(items,@BatchID,@UserID)





参见 SET @local_variable(Transact-SQL) [ ^ ]


这篇关于我的商店程序无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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