Sql-server – Replace NULLs with value

insertisnullnullreplacesql server

Here is my temporary table:

CREATE TABLE #test123(
    c1 float,
    c2 float,
    c3 float,
    c4 float,
    c5 float
);

INSERT #test123(c1,c2,c3,c4,c5)
VALUES (2,3,NULL,1,2),
       (2,NULL,NULL,1,2),
       (2,3,NULL,NULL,2),
       (NULL,3,NULL,1,NULL),
       (2,3,NULL,1,2);

When I run the following querys to replace all NULLs in the first column

INSERT INTO #test123 (c1) VALUES (ISNULL(c1,0));

or

INSERT INTO #test123 (c1) SELECT CASE WHEN c1 IS NULL THEN 0  END AS c1;

I receive both time the error "Invalid column name 'c1'."

The Syntax (source) of INSERT INTO is:

INSERT INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...); 

Best Answer

If you want to update values, you need to use UPDATE, not INSERT:

UPDATE #test123 
SET c1 = 0
WHERE c1 IS NULL ;