Reputation: 95
I have a column (attr14
: having decimal(10,5)
as type) in an SQL server table that has many NULL values that i want to replace with 0 values, in SQL Server i execute a query like this :
UPDATE [myds].[dbo].[mytable]
SET [myds].[dbo].[mytable].[attr14] = 0
WHERE [myds].[dbo].[mytable].[attr14] = NULL;
But that lead to the following error :
Error converting data type varchar to numeric.
if i run :
UPDATE [myds].[dbo].[mytable]
SET [myds].[dbo].[mytable].[attr14] = 0.0
WHERE [myds].[dbo].[mytable].[attr14] = NULL;
0 lines were affected
Then no line is affected while there is NULL values in the attr14
column
Upvotes: 0
Views: 468
Reputation: 5398
If your column attr14 is of datatype decimal(10,5) then you can try like this.
USE [myds]
UPDATE [dbo].[mytable]
SET [attr14] = 0.0
WHERE [attr14] IS NULL;
Upvotes: 1