SSRS 将多行合并为一

SSRS Combine Multiple Rows into One

我正在整理一份 SSRS 报告,其中将显示人们欠他们的会费。

现在我会根据每个人是否有欠费、滞纳金或退款得到不同的行。

我需要能够将它们显示为一行而不是三行。

我的列表当前显示为:

Member ID | Name | Date | Dues | Refund | Late Fee | Inv ID | Total
123456789 | John | 2015 | 0 | ------ | -------- | INV 01 | 0
123456789 | John | 2015 | ---- | ------ | ----- | INV 01 |  
987654321 | Jane | 2015 | 0 | ------ | -------- | INV 02 | 0

我希望它显示为:

Member ID | Name | Date | Dues | Refund | Late Fee | Inv ID | Total
123456789 | John | 2015 | 0 | ------ | ----- | INV 01 | 0
987654321 | Jane | 2015 | 0 | ------ | -------- | INV 02 | 0

--澄清-- 现在唯一的方法就是通过物品的描述来判断物品是什么;即,项目名称将是会员费、会员滞纳金或会员退款,最终形成不同的项目。

然后您需要汇总您的数据:

select member_id, name, date, sum(dues) dues
     , sum(refund) refund, sum(late_fee) late_fee
     , inv_id, sum(total) total
  from your_table
 group by member_id, name, date, inv_id;

我终于让它与以下 SQL 一起工作:

WITH cte_Intial AS (
    SELECT
        c.firstname
        ,c.lastname
        ,c.new_memberid
        ,s.new_invid
        ,CASE
            WHEN sd.productidname LIKE 'Late%' THEN NULL
            ELSE s.totalamount
        END AS "Dues"
        ,CASE
            WHEN sd.productidname LIKE 'Late%' THEN s.totalamount
            ELSE null
        END AS "LateFee"
        ,s.new_purchasedate
        ,s.name
        ,sd.productidname
    FROM
        Filteredcontact AS c
        INNER JOIN FilteredSalesOrder AS s ON c.new_memberid = s.new_memberid
        INNER JOIN FilteredSalesOrderDetail AS sd ON s.salesorderid = sd.salesorderid
    WHERE
        c.new_divisioncode = 'A' AND sd.productidname LIKE '%Dues%' AND
        DATEPART(YEAR, CAST(s.new_purchasedate AS DATE)) = 2015
)
SELECT
    firstname
    ,lastname
    ,new_memberid
    ,ISNULL(MAX(Invoice), '')/* + ' ' + ISNULL(MAX(Late), '')*/ as Invoice
    ,MAX(Dues) as Dues
    ,MAX(LateFee) as LateFee
    ,new_purchasedate
    ,name
FROM 
    cte_Intial
GROUP BY
    firstname
    ,lastname
    ,new_memberid
    ,new_purchasedate
    ,name