"Conversion failed when converting the varchar value 'NULL' to data type int" "Conversion failed when converting the varchar value 'NULL' to data type int" sql-server sql-server

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


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')


The fact that it mentions "the varchar value 'NULL'" indicates that you're trying to set the column's value to the string "NULL" instead of the value NULL.

Look in your statement for the word NULL surrounded by quotes. You'll need to remove these quotes.


Start commenting stuff out one at a time until it stops bombing. Or, take a look and see which value you're passing is NULL for an int column.