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

  • I am using SQL Server2005

    SELECT FIELD1+ ' : ' + FIELD2 as CONCATFIELD

    FROM MYFILE

    generates the error Conversion failed when converting the varchar value ' : ' to data type int.

    How can i resolve this ?

  • At least one of your fielsd is an integer datatype. T-SQL won't do implicit type conversion

  • That is correct. FIELD1 is an integer field.

    I want to concatenate an integer field and a varcharfield. how do i do this ?

  • OK i find it myself

    STR(FIELD1) does the job

  • Look up CAST() and Convert() in BOL - that should give you a start.

    HTH

    Andrew

  • Thanks !

  • pvc (12/30/2008)


    OK i find it myself

    STR(FIELD1) does the job

    STR() without any length argument gives you a 10 character result where the string is padded with leading blanks. You probably would want to use CAST() instead to have more control over your result or specify a length argument for STR().

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

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

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