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
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
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
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.