我有以下@temp表:
------------------------------------
|Condition_ID Operator Order |
| 1 == 1 |
| 2 <> 3 |
| 3 == 2 |
------------------------------------
我想实现一个SELECT CASE,它将根据Operator
输出某个消息然而,这会引发Incorrect syntax near the keyword 'PRINT'.
错误。
SELECT CASE
WHEN Operator LIKE '=='
THEN PRINT 'EQUALS'
WHEN Operator LIKE '<>'
THEN PRINT 'NOT EQUALS'
END AS Operator
FROM @temp
我做错了什么?
答案 0 :(得分:1)
您不能混用PRINT
和SELECT
SELECT CASE WHEN Operator LIKE '=='
THEN 'EQUALS'
WHEN Operator LIKE '<>'
THEN 'NOT EQUALS'
END AS Operator
FROM @temp
答案 1 :(得分:1)
您只需要移除PRINT
SELECT CASE
WHEN Operator LIKE '=='
THEN 'EQUALS'
WHEN Operator LIKE '<>'
THEN 'NOT EQUALS'
END AS Operator
FROM @temp
您无法在PRINT
内使用SELECT
,而且您不需要 - SELECT
将为您检索适当的值。
答案 2 :(得分:0)
这有效::
SELECT CASE
WHEN opr LIKE '=='
THEN 'EQUALS'
WHEN opr LIKE '<>'
then 'NOT EQUALS'
else
'wrong i/p'
end
as operator
FROM tbl1;
答案 3 :(得分:0)
试试这个,没有打印选项
SELECT CASE
WHEN Operator LIKE '=='
THEN 'EQUALS'
WHEN Operator LIKE '<>'
THEN 'NOT EQUALS'
END AS Operator
FROM @temp