3

我在 SQL Server 2005 中有这个查询(我仅使用了更方便的 2008 插入方法),我需要在网格输出中将 (null) 替换为 0。

无论如何要这样做?

4

1 回答 1

4

您将使用该ISNULL()功能。请参阅SQL 小提琴

SELECT 'lessonid          response ->'
   , isnull([0], 0) as [0]
  , isnull([1], 0) as [1]
  , isnull([2], 0) as [2]
  , isnull([3], 0) as [3]
  , isnull([4], 0) as [4]
FROM (
    SELECT lessonid AS 'lessonid          response ->'
        ,ISNULL(response,0) as response
        ,count(response) AS respcnt
    FROM tblRChoices
    GROUP BY lessonid
        ,response
    ) TableResponse
PIVOT(SUM(respcnt) FOR response IN (
            [0]
            ,[1]
            ,[2]
            ,[3]
            ,[4]
            )) ResponsePivot
于 2012-07-12T19:40:29.467 回答