如何删除包含所有" 0"的数据透视表行值

时间:2017-02-22 13:35:41

标签: sql-server pivot-table

我使用以下查询创建了一个数据透视表:

declare @custnum nvarchar(7) = '   1124'
declare @yr smallint = 2016

SELECT 'Customer Qty Returned' as Description,'RO' as UnitOfMeasure,
       COALESCE(Jan,0)Jan,
       COALESCE(Feb,0)Feb,
       COALESCE(Mar,0)Mar,
       COALESCE(Apr,0)Apr,
       COALESCE(May,0)May,
       COALESCE(Jun,0)Jun,
       COALESCE(Jul,0)Jul,
       COALESCE(Aug,0)Aug,
       COALESCE(Sep,0)Sep,
       COALESCE(Oct,0)Oct,
       COALESCE(Nov,0)Nov,
       COALESCE(Dec,0)Dec
FROM(
       SELECT ri.u_m,
              CASE WHEN ri.return_item = '1' and ri.u_m = 'RO'
                   then ROUND(ri.qty_to_return,0)
              END AS QtyReturned
             ,left(datename(month,r.rma_date),3) AS RetMonth
       FROM rma r
           INNER JOIN rmaitem ri ON r.rma_num = ri.rma_num
       WHERE r.cust_num = @custnum and YEAR(r.rma_date) = @yr 
)
AS R
PIVOT
(
SUM(QtyReturned)
FOR RetMonth
IN (Jan,Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec)
)AS pvt

这是表格的样子: enter image description here

在此特定示例中,对于此特定客户,所有值均为" 0"。 我的问题是如何隐藏或阻止所有" 0"我桌上的价值观? 正如你所知,我是一个新手,并希望对这个问题有任何见解。

0 个答案:

没有答案