Creating variables in sql stored procedures

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jyothi1105
    New Member
    • Apr 2007
    • 14

    Creating variables in sql stored procedures

    Hi,

    I want to create a sql stored procedure wherein the local variable should store the maximum value of the column and increment it everytime the record is entered into table.
    i created it like this

    create procedure insertevent(... ...)
    declare @num as int
    set @num="select count(EventID) from Event"
    set @num=@num+1
    as
    begin
    insert Event(.......) values (....)
    end
    iam getting the error as" error converting the varchar value "select statement" from Event table of column of datatype int"
    Here, the Event table column EventID is also int.

    can u help me?
  • kenobewan
    Recognized Expert Specialist
    • Dec 2006
    • 4871

    #2
    I don't believe that you can execute a query from a parameter, this is the problem with your procedure.

    Comment

    Working...