stored procedure type conversion error

  • create procedure sample_proc(@session_id int)

    as

    begin

    declare @sql_stmt varchar(4000)

    set @sql_stmt =

    'select * from session ' +char(13)+

    'where session_id =' + @session_id

    exec(@sql_stmt)

    end

    when i run the stored proc

    sample_proc 57198010

    Server: Msg 245, Level 16, State 1, Procedure sample_proc, Line 5

    Syntax error converting the varchar value 'select * from session

    where session_id ='' to a column of data type int.

  • Try

    create procedure sample_proc(@session_id int)

    as

    begin

    declare @sql_stmt varchar(4000)

    set @sql_stmt =

    'select * from session ' +char(13)+

    'where session_id =' + CONVERT(varchar,@session_id )

    exec(@sql_stmt)

    end

    Gary Johnson

    Microsoft Natural Language Group

    DBA, Sr. DB Engineer




    Gary Johnson
    Microsoft Natural Language Group
    DBA, Sr. DB Engineer

    This posting is provided "AS IS" with no warranties, and confers no rights. The opinions expressed in this post are my own and may not reflect that of my employer.

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

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