我正在使用实时查看程序来进行SQL查询(并让我编辑代码的一部分)
目前代码是:
SELECT
[LogonName] AS [Logon name],
[LogonExtension] AS [Logon extension],
[VoiceReady] AS [Ready for Voice],
[CallState] AS [Call state]
FROM
[AgentPerformance]
WHERE
(AgentID IN (1, 2, 3))
返回:
现在我的问题是,有没有办法改变返回的“呼叫状态”值,让我们说忙,免费,处理等...(有3个不同的值)。
我试过例如:
SELECT
[LogonName] AS [Logon name],
[LogonExtension] AS [Logon extension],
[VoiceReady] AS [Ready for Voice],
[CallState] AS [Call state]
FROM
[AgentPerformance]
WHERE
(AgentID IN (1, 2, 3))
SELECT
CASE
WHEN CallState = 0 THEN 'No'
WHEN CallState = 1 THEN 'Yes
ELSE 'Maybe'
END AS kakaduu
FROM
AgentPerformance
但这对我不起作用。
答案 0 :(得分:3)
您的CASE
表达式必须与其他列一起位于SELECT
列表中。第二个SELECT
在您的示例中是不正确的语法。
所以,试试这个:
SELECT [LogonName] AS [Logon name], [LogonExtension] AS [Logon extension], [VoiceReady] AS [Ready for Voice], [CallState] AS [Call state],
CASE
WHEN CallState = 0 then 'No'
WHEN CallState = 1 then 'Yes'
ELSE 'Maybe'
END
AS kakaduu
FROM [AgentPerformance]
WHERE AgentID IN (1, 2, 3)