Skip to main content
Tweeted twitter.com/StackDBAs/status/722582815351644160
deleted 13 characters in body
Source Link
Hannah Vernon
  • 70.5k
  • 22
  • 177
  • 321

I have a single table like

    createCREATE tableTABLE 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 NameName;

Now I want to update my Name column like this:

Update MyTable
set name = case ID when 1 then DEFAULT ENDEND;

But I am getting this error:

Incorrect syntax near the keyword 'DEFAULT'

How can I use UPDATEUPDATE with DEFAULTDEFAULT statement in CASEthe CASE clause?

I am using SQL Server 2014.

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 error

Incorrect syntax near the keyword 'DEFAULT'

How can I use UPDATE with DEFAULT statement in CASE clause?

I am using SQL Server 2014.

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?

Post Reopened by Martin Smith, Hannah Vernon, Paul White
added 196 characters in body
Source Link

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 error

Incorrect syntax near the keyword 'DEFAULT'

How can I use UPDATE with DEFAULT statement in CASE clause?

I am using SQL Server 2014.

I have a single table like

create table Mytable (ID int identity, Name nvarchar(10))

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 error

Incorrect syntax near the keyword 'DEFAULT'

How can I use UPDATE with DEFAULT statement in CASE clause?

I am using SQL Server 2014.

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 error

Incorrect syntax near the keyword 'DEFAULT'

How can I use UPDATE with DEFAULT statement in CASE clause?

I am using SQL Server 2014.

Post Closed as "Needs details or clarity" by Paul White
added 4 characters in body
Source Link
Paul White
  • 90.3k
  • 30
  • 424
  • 663

I have a single table like

create table Mytable (ID int identity, Name nvarhcarnvarchar(10))

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 error

Incorrect syntax near the keyword 'DEFAULT'

How can I use UPDATE with DEFAULT statement in CASE clause  ?

I am using MSSQLSQL Server 2014.

I have a single table like

create table Mytable (ID int identity, Name nvarhcar(10))

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 error

Incorrect syntax near the keyword 'DEFAULT'

How can I use UPDATE with DEFAULT statement in CASE clause  ?

I am using MSSQL 2014.

I have a single table like

create table Mytable (ID int identity, Name nvarchar(10))

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 error

Incorrect syntax near the keyword 'DEFAULT'

How can I use UPDATE with DEFAULT statement in CASE clause?

I am using SQL Server 2014.

added 3 characters in body; edited tags
Source Link
Kin Shah
  • 62.4k
  • 6
  • 122
  • 241
Loading
Source Link
Loading