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

前端 未结 2 1208
失恋的感觉
失恋的感觉 2021-01-05 11:52

I got this error when trying run my sql query...

Conversion failed when converting the varchar value \'Id\' to data type int

相关标签:
2条回答
  • 2021-01-05 12:05

    Try casting Id column to INT

    SELECT *
    FROM History
    INNER JOIN Header
    ON cast(History.Id AS int) = Header.docId
    
    0 讨论(0)
  • 2021-01-05 12:10

    In your Join condition am sure one column is of Integer type and other one is Varchar type.

    ON History.Id = Header.docId
    

    since Int has higher precedence than varchar, Varchar column will be implicitly converted to Int

    So explicitly convert the Int column to varchar.

    ON History.Id = cast(Header.docId as varchar(50))
    

    I have considered Header.docId as Int type if no, then convert History.Id to varchar

    0 讨论(0)
提交回复
热议问题