需要SQL Server 2008帮助

时间:2016-11-14 12:48:20

标签: sql sql-server sql-server-2008

我对SQL很陌生,而且我被卡住了。我在SQL Server 2008中有以下查询可以处理,但我需要将“ErrorHandling”的结果设置为在返回1的结果时显示为0,但保留其他任何结果(结果进入网页所以不能有'null'或者根本没有显示任何结果。)

False

这是我需要的输出格式:

Results

我尝试过使用USE IDS_Queues SELECT FSState AS [hersham], COUNT(FSState) AS Totals FROM hersham_idsinfo WHERE (FSState = 'Loading') OR (FSState = N'Replicating') OR (FSState = N'ErrorHandling') OR (FSState = N'WaitingToReceiveMulticast')OR (FSState = N'GeneratingSubfiles') GROUP BY FSState ,但似乎无法让它发挥作用。任何帮助将不胜感激。

由于 麦克

1 个答案:

答案 0 :(得分:0)

CASE表达式应该可以正常工作:

SELECT  [hersham],
        CASE 
            WHEN [hersham] = N'ErrorHandling' AND Totals = 1 THEN 0 
            ELSE Totals
        END Totals
FROM (  SELECT  FSState AS [hersham], 
                COUNT(FSState) AS Totals
        FROM hersham_idsinfo
        WHERE FSState IN (N'Loading',N'Replicating',N'ErrorHandling',
                          N'WaitingToReceiveMulticast',N'GeneratingSubfiles')) X
;