SQL Server CASE .. WHEN .. IN statement SQL Server CASE .. WHEN .. IN statement sql-server sql-server

SQL Server CASE .. WHEN .. IN statement


CASE AlarmEventTransactions.DeviceID should just be CASE.

You are mixing the 2 forms of the CASE expression.


Thanks for the Answer I have modified the statements to look like below

SELECT     AlarmEventTransactionTable.TxnID,     CASE     WHEN DeviceID IN('7', '10', '62', '58', '60',            '46', '48', '50', '137', '139',             '141', '145', '164') THEN '01'    WHEN DeviceID IN('8', '9', '63', '59', '61',            '47', '49', '51', '138', '140',            '142', '146', '165') THEN '02'             ELSE 'NA' END AS clocking,     AlarmEventTransactionTable.DateTimeOfTxnFROM     multiMAXTxn.dbo.AlarmEventTransactionTable


Try this...

SELECT    AlarmEventTransactionTableTable.TxnID,    CASE        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

Just remove highlighted string

SELECT AlarmEventTransactionTableTable.TxnID, CASE AlarmEventTransactions.DeviceID WHEN DeviceID IN('7', '10', '62', '58', '60', ...)