使用Rollup时重命名Null值

时间:2018-06-15 16:48:37

标签: sql rollup

我有这个脚本,它是一个用于创建动态“数据输入签名验证”工作的测试。我想用'Total'代替'NULL'。 这是我在不同论坛上在网上找到的内容,但我无法取代它。

USE [LA_VOTER]    
GO    
/****** Object:  StoredProcedure [Temp].[dmv_import]    Script Date: 6/14/2018 
11:23:09 AM ******/    
SET ANSI_NULLS ON    
GO    
SET QUOTED_IDENTIFIER ON    
GO    

ALTER PROCEDURE [Temp].[dmv_import]    
    -- Add the parameters for the stored procedure here    
     @date date = null    
     ,@import_type varchar(5) = null        
AS    
BEGIN    
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.    
    SET NOCOUNT ON;    
declare @date_work date     
if @date is null     
set @date_work = getdate()    
else    
Set @date_work = @date         
SELECT case when convert(varchar(6),vi.import_code) = null then 'Total' else vi.import_code end as 'Category'    
,sum(case when convert(date,vi.createdate,101) = @date_work then 1 else 0 end) as 'received'    
,sum(case when convert(date,vi.processed_date,101) = @date_work then 1 else 0 end) as 'processed'    
FROM DIMSNet.dbo.voter_import vi    
WHERE     
vi.import_type in ('INET', 'DUP', 'DMV')    
AND vi.import_type = @import_type     
AND import_code < 13     
GROUP BY import_code with rollup     
END

运行时,此脚本输出以下内容:

enter image description here

Th脚本大部分都在工作。

我要做的是在第一列中获取NULL值以计算脚本的总累积量。我不太确定我做错了什么。任何帮助或建议将不胜感激。

0 个答案:

没有答案