user3354456
user3354456

Reputation: 13

Msg 102, Level 15, State 1, Line 3 Incorrect syntax near '='

I want to select from ReceiveNote if fromloc = 1 then print Factory else have to print Other

SELECT PurDate,
case ReceiveNote.FromLOC
when ReceiveNote.FromLOC = '1' THEN 'Factory'
when ReceiveNote.FromLOC = '2' THEN 'Other'
else ''
end as FromLOC FROM tbl1

Upvotes: 1

Views: 1735

Answers (2)

Amir Keshavarz
Amir Keshavarz

Reputation: 3108

SELECT PurDate,
case when ReceiveNote.FromLOC = '1' THEN 'Factory'
when ReceiveNote.FromLOC = '2' THEN 'Other'
else ''
end as FromLOC FROM tbl1

Upvotes: 0

Alexander
Alexander

Reputation: 3179

You already specified field after CASE word. No need to specify it again.

SELECT PurDate,
       CASE ReceiveNote.FromLOC
            WHEN '1' THEN 'Factory'
            WHEN '2' THEN 'Other'
            ELSE ''
       END AS FromLOC 
  FROM tbl1

And here is documentation on CASE for tsql

Upvotes: 1

Related Questions