Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

store procedue issue Expand / Collapse
Author
Message
Posted Friday, August 15, 2014 9:35 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, August 15, 2014 9:29 AM
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.
Post #1603746
Posted Friday, August 15, 2014 9:46 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 7:58 AM
Points: 5,369, Visits: 9,919
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
Post #1603754
Posted Friday, August 15, 2014 10:12 AM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Today @ 4:10 PM
Points: 3,576, Visits: 8,024
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.
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?

Forum Etiquette: How to post data/code on a forum to get the best help
Post #1603771
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse