Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


store procedue issue


store procedue issue

Author
Message
narasiman1986
narasiman1986
Forum Newbie
Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)

Group: General Forum Members
Points: 1 Visits: 2
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.
John Mitchell-245523
John Mitchell-245523
SSCertifiable
SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)

Group: General Forum Members
Points: 7414 Visits: 15114
There's all sorts of things. You're trying to use a stored procedure (OH_Message) as a function. You're trying to assign a value to a variable (@status) without a SET or SELECT keyword. You're trying to use a column (items) from a table without a FROM clause. And, although it's not actually incorrect, this is bad practice: you're using a cursor where a SET based operation is likely to be simpler and faster.

John
Luis Cazares
Luis Cazares
SSCrazy Eights
SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)

Group: General Forum Members
Points: 8505 Visits: 18112
And John missed the part where OH_Message doesn't expects parameters and you're sending parameters. You're not using @Stud_id which is the base of your cursor and you have a begin with no corresponding end.
What are you trying to do? Maybe we can help to simplify the logic and correct the code.
Please read the article linked in my signature to get better help.


Luis C.
General Disclaimer:
Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?


How to post data/code on a forum to get the best help: Option 1 / Option 2
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search