store procedue issue

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

  • 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

  • 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

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply