SQL Server CASE .. WHEN .. IN 语句 [英] SQL Server CASE .. WHEN .. IN statement
本文介绍了SQL Server CASE .. WHEN .. IN 语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 SQL Server 2005 上,我试图查询这个选择语句
On SQL server 2005 I am trying to query this select statement
SELECT AlarmEventTransactionTableTable.TxnID,
CASE AlarmEventTransactions.DeviceID
WHEN DeviceID IN( '7', '10', '62', '58',
'60', '46', '48', '50',
'137', '139', '142', '143', '164' )
THEN '01'
WHEN DeviceID IN( '8', '9', '63', '59',
'61', '47', '49', '51',
'138', '140', '141', '144', '165' )
THEN '02'
ELSE 'NA'
END AS clocking,
AlarmEventTransactionTable.DateTimeOfTxn
FROM multiMAXTxn.dbo.AlarmEventTransactionTable
它返回下面的错误
消息 156,级别 15,状态 1,第 4 行关键字IN".
Msg 156, Level 15, State 1, Line 4 Incorrect syntax near the keyword 'IN'.
请给我一些关于我的代码可能有什么问题的建议.
Please give me some advice on what could be wrong with my code.
推荐答案
CASE AlarmEventTransactions.DeviceID
应该只是 CASE
.
您正在混合 两种形式的 CASE
表达式.
You are mixing the 2 forms of the CASE
expression.
这篇关于SQL Server CASE .. WHEN .. IN 语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文