0

我有以下@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

我究竟做错了什么?

4

4 回答 4

1

你不能混合PRINTSELECT

SELECT CASE WHEN Operator LIKE '=='
            THEN 'EQUALS'
            WHEN Operator LIKE '<>'
            THEN 'NOT EQUALS'
       END AS Operator
FROM @temp
于 2012-11-27T10:56:27.247 回答
1

你只需要删除PRINT

SELECT CASE
    WHEN Operator LIKE '=='
        THEN 'EQUALS'
    WHEN Operator LIKE '<>'
        THEN 'NOT EQUALS'
END AS Operator
FROM @temp

您不能在 a 中使用 a PRINTSELECT也不需要 -SELECT将为您检索适当的值。

于 2012-11-27T11:00:35.750 回答
0

这工作::

   SELECT CASE
    WHEN opr LIKE '=='
        THEN 'EQUALS'
    WHEN opr LIKE '<>'
        then 'NOT EQUALS'
    else
        'wrong i/p'
    end
as operator
FROM tbl1;
于 2012-11-27T11:05:12.673 回答
0

试试这个,没有打印选项

SELECT CASE 
        WHEN Operator LIKE '=='
        THEN 'EQUALS'
        WHEN Operator LIKE '<>'
        THEN 'NOT EQUALS'
   END AS Operator
   FROM @temp
于 2012-11-27T11:07:05.117 回答