消息102,级别15,状态1,行3'='附近的语法不正确

时间:2014-03-01 08:21:29

标签: sql sql-server

如果fromloc = 1,我想从ReceiveNote中选择,然后打印工厂,否则必须打印其他

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

2 个答案:

答案 0 :(得分:1)

您已在CASE字后指定了字段。无需再次指定。

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

here is documentation on CASE for tsql

答案 1 :(得分:0)

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