-1

I have very simple query:

update dbo.myTable
    set [field1] = case when [field2] <> '' 
                     then [field1] = SUBSTRING([field2],1,6) 
                     ELSE [field1] 
                   end

Which gives:

Incorrect syntax near ''

I've already explored Incorrect syntax near '' and tried everything there.

Microsoft SQL Server Enterpris, 14.0.3294.2

eshirvana
  • 23,227
  • 3
  • 22
  • 38
Hrvoje
  • 13,566
  • 7
  • 90
  • 104

1 Answers1

1

here is the right syntax, no need to assign it again inside the case statement:

update dbo.myTable
    set [field1] = case when [field2] <> '' 
                     then SUBSTRING([field2],1,6) 
                     ELSE [field1] 
                   end
eshirvana
  • 23,227
  • 3
  • 22
  • 38