简体   繁体   English

更改SQL查询中的返回值

[英]Change returned value in SQL query

I am working with real time viewing program that makes SQL queries (and let me edit bit of the code) 我正在使用实时查看程序来进行SQL查询(并让我编辑代码的一部分)

At the moment code is: 目前代码是:

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))

This returns: 返回:

在此输入图像描述

Now my question is that is there any way to change the returned "call state" values to let's say busy, free, handling etc... (there are 3 different values). 现在我的问题是,有没有办法改变返回的“呼叫状态”值,让我们说忙,免费,处理等...(有3个不同的值)。

I have tried for example: 我试过例如:

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

But this didn't work for me. 但这对我不起作用。

Your CASE expression need to be in SELECT list along with another columns. 您的CASE表达式需要与其他列一起位于SELECT列表中。 second SELECT was incorrect syntax in your example. 第二个SELECT在您的示例中是不正确的语法。

So, try this: 所以,试试这个:

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) 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM