Conversion failed when converting the varchar value '12.00' to data type int.

  • DECLARE @mv_mark varchar(500),

    @ob_mark varchar(500),

    @tot varchar(500),

    @mv_mark1 varchar(500),

    @ob_mark1 varchar(500)

    SELECT @mv_mark =mv_mark

    FROM internal_nontheory_mark

    WHERE roll_no = '11csu002' AND regulation_sub_id = 15849

    SELECT @ob_mark = ob_mark

    FROM internal_nontheory_mark

    WHERE roll_no = '11csu002' AND regulation_sub_id = 15849

    SET @mv_mark1 = CAST(COALESCE(@mv_mark, 0) AS VARCHAR)

    SET @ob_mark1 = CAST(COALESCE(@ob_mark, 0) AS VARCHAR)

    select @mv_mark1,@ob_mark1

    when i execute it returns 'Conversion failed when converting the varchar value '0.00' to data type int.

    what should i do?

    can anyone help me?

  • 12.00 is not an integer. so you can convert this value to an int.

    if it is 12 then you can do it.:hehe:

  • yes i know that.but i need '12.00' as result.so what should i change here?

  • DECLARE @mv_mark varchar(500),

    @ob_mark varchar(500),

    @tot varchar(500),

    @mv_mark1 varchar(500),

    @ob_mark1 varchar(500)

    SELECT @mv_mark =mv_mark

    FROM internal_nontheory_mark

    WHERE roll_no = '11csu002' AND regulation_sub_id = 15849

    SELECT @ob_mark = ob_mark

    FROM internal_nontheory_mark

    WHERE roll_no = '11csu002' AND regulation_sub_id = 15849

    SET @mv_mark1 = CAST(COALESCE(@mv_mark, '0') AS VARCHAR)

    SET @ob_mark1 = CAST(COALESCE(@ob_mark, '0') AS VARCHAR)

    select @mv_mark1,@ob_mark1

  • Mr. Kapsicum (6/14/2013)


    DECLARE @mv_mark varchar(500),

    @ob_mark varchar(500),

    @tot varchar(500),

    @mv_mark1 varchar(500),

    @ob_mark1 varchar(500)

    SELECT @mv_mark =mv_mark

    FROM internal_nontheory_mark

    WHERE roll_no = '11csu002' AND regulation_sub_id = 15849

    SELECT @ob_mark = ob_mark

    FROM internal_nontheory_mark

    WHERE roll_no = '11csu002' AND regulation_sub_id = 15849

    SET @mv_mark1 = CAST(COALESCE(@mv_mark, '0') AS VARCHAR)

    SET @ob_mark1 = CAST(COALESCE(@ob_mark, '0') AS VARCHAR)

    select @mv_mark1,@ob_mark1

    Check if this helps.

    your coalesce is giving you problem here. have handled your varchar and int conversion by making your 0 in coalesce as varchar.

  • thank you very much sir...it works well .and i have to sum both the values so i tried this but the same problem?

    SET @total = CAST(( CAST(ISNULL(@mv_mark, 0) AS INT) + CAST(ISNULL(@ob_mark, 0) AS INT)) AS VARCHAR)

  • what you are trying to do here is to add a varchar value to int value. which is not possible.

    think a little bit more logical. if you dont get the answer, will surely help you then .

  • thank u sir.i got it

Viewing 8 posts - 1 through 7 (of 7 total)

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