I have a single table like
CREATE TABLE Mytable (ID int identity, Name nvarchar(10));
GO
INSERT INTO MyTable (Name) VALUES ('test1');
INSERT INTO MyTable (Name) VALUES ('test2');
GO
ALTER TABLE MyTable ADD CONSTRAINT DF_Name DEFAULT('test') FOR Name;
Now I want to update my Name column like this:
Update MyTable
set name = case ID when 1 then DEFAULT END;
But I am getting this error:
Incorrect syntax near the keyword 'DEFAULT'
How can I use UPDATE
with DEFAULT
statement in the CASE
clause?
NULL
in all the rows (except for the one withid=1
which would get the default value)? Did you really want that?