Question : SQL Update Query Not working

I am trying to replace all nulls in a field with -1, however it is an INT field and I get the error "Msg 245, Level 16, State 1, Line 1
Conversion failed when converting the varchar value 'NULL' to data type int." below is my code.
1:
2:
3:
4:
UPDATE [Checklist].[dbo].[InspectionResponses]
 SET [ReportType]='-1' 
 WHERE [ReportType] = 'NULL'
GO

Answer : SQL Update Query Not working

Why do you have the NULL and the -1 as a string? That is why the problem is coming, like I posted above if you just use IS NULL to see whether a column is null, it will solve the problem. Also on the UPDATE statement instead of setting ReportType to '-1' you might want to use just -1.

See code

Regards,
Nachi
1:
2:
3:
UPDATE [Checklist].[dbo].[InspectionResponses]
 SET [ReportType]= -1
 WHERE [ReportType] IS NULL
Random Solutions  
 
programming4us programming4us