“Conversion failed when converting the varchar value 'NULL' to data type int”

后端 未结 4 879

When I insert records into a long table,I am getting the error \"Conversion failed when converting the varchar value \'NULL\' to data type int\" How can I determine which co

4条回答
  •  说谎
    说谎 (楼主)
    2021-01-02 13:23

    If the value is truly NULL, there wouldn't be a conversion error. However, you have a string = "NULL" then you would get this error.

    What you could do is...

    NullIf(YourValueHere, 'NULL')
    

    NullIf returns the value of the first parameter if it is not the same as the second parameter. If the parameters are the same, NullIf will return NULL.

    Ex:

    Select NullIf('Any Value', 'NULL')
    
    Select NullIf('null','null')
    

    The first will return 'Any Value' and the second will return NULL (not 'null')

提交回复
热议问题