Problem in dataconversion

  • The Following procedure gives error 8114 at line 10 : if instead of @sec_id i simply write 1 as sec id it works else it gives error unable to convert data type varchar to bigint . Please Help .

    CREATE PROCEDURE [dbo].[Get_Ques_id_for_can]

    (@candidate_id varchar(max),@Exam_id varchar(max),@sec_id bigint)

    AS

    BEGIN

    declare @table_query varchar(max)

    declare @table varchar(max)

    set @table=@candidate_ID+@Exam_id

    set @table_query='SELECT [ID], [Question_ID] FROM ['+@table+'] WHERE [Section_ID]='+@sec_id

    EXEC(@table_query)

    END

  • Try

    set @table_query='SELECT [ID], [Question_ID] FROM ['+@table+'] WHERE [Section_ID]='+convert(@sec_id as varchar(50))

    ----------------------------------------------------------------------------------------------------------------------------------------------------
    Roshan Joe

    Jeff Moden -Forum Etiquette: How to post data/code on a forum to get the best help[/url]

  • In database [Section_ID] has datatype bigint

  • You are using dynamic string so the type of the variable does not matter.

    Moreover you are getting this error when trying to concatenate the integer variable with varchar string 'Select ....'

    ----------------------------------------------------------------------------------------------------------------------------------------------------
    Roshan Joe

    Jeff Moden -Forum Etiquette: How to post data/code on a forum to get the best help[/url]

  • It worked . Thanks a lot! 🙂

Viewing 5 posts - 1 through 4 (of 4 total)

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