在SQL中根据日期比较数据,然后在SSRS中运行

时间:2018-08-03 08:51:39

标签: sql sql-server reporting-services compare

screenshot

HI 我在下面创建了一条sql,以便比较客户上一时期是否有库存,我需要显示客户在此期间而不是上一时期的库存 我只是想能够运行一个仅列出PERIOD3 CUSTOMER1的报告,即使我指定的日期包括期间1-4

PERIOD1 CUSTOMER1
PERIOD2 NULL
PERIOD3 CUSTOMER1
PERIOD4 CUSTOMER1

我不知道如何在报告中仅取回PERIOD3 CUSTOMER1数据,最佳方法是什么?在SSRS报告中或原始SQL中,然后可以将其添加到SSRS报告中

SELECT  C43.ACCOUNT15_C43, 
        C43.RECODATE_C43, 
        SNAPSHOT.WORDREF1_C43, 
        CUSTOMER.NADNAME, 
        CUSTOMER.NADPOCODE, 
        CUSTOMER.ATTVALFROM_T10
FROM     
    (
        SELECT  ACCOUNT15_C43, 
                RECODATE_C43
        FROM      dbo.MBC430
        GROUP BY 
                ACCOUNT15_C43, 
                RECODATE_C43
    ) AS C43 
INNER JOIN
    (
        SELECT  dbo.MAA930.ACCOUNT15_NAD, 
                dbo.MAA930.NADACCNO, 
                dbo.MAA930.NADNAME, 
                dbo.MAA930.NADPOCODE, 
                T10.ATTVALFROM_T10
        FROM dbo.MAA930 
        LEFT OUTER JOIN
            (
                SELECT  ACCOUNT15_T10, 
                        CUSTOMERLONG_T10, 
                        ATTVALFROM_T10
                FROM     
                dbo.MBT100
                WHERE ATTRIBCODE_T10 = 'CU1'
            ) AS T10 
            ON dbo.MAA930.ACCOUNT15_NAD = T10.ACCOUNT15_T10 
            AND dbo.MAA930.NADACCNO = T10.CUSTOMERLONG_T10
        WHERE dbo.MAA930.NADSEQNO = '999' 
        AND dbo.MAA930.NADTYPE = '23'
    ) AS CUSTOMER 
    ON C43.ACCOUNT15_C43 = CUSTOMER.ACCOUNT15_NAD 
LEFT OUTER JOIN
    (
        SELECT  MBC430_1.RECODATE_C43, 
                MBC430_1.WORDREF1_C43
        FROM     dbo.MBB010 
        INNER JOIN dbo.MBC430 AS MBC430_1 
            ON dbo.MBB010.PARTNO = MBC430_1.PARTNO_C43 
            AND dbo.MBB010.ACCOUNT15 = MBC430_1.ACCOUNT15_C43
        GROUP BY 
            dbo.MBB010.PRE_B01, 
            dbo.MBB010.PARTYPE, 
            MBC430_1.WORDREF1_C43, 
            MBC430_1.RECODATE_C43
        HAVING dbo.MBB010.PRE_B01 = 'T' 
        AND dbo.MBB010.PARTYPE = 'FG'
        AND NOT MBC430_1.WORDREF1_C43 = ' '
    ) AS SNAPSHOT 
    ON CUSTOMER.NADACCNO = SNAPSHOT.WORDREF1_C43 
    AND C43.RECODATE_C43 = SNAPSHOT.RECODATE_C43

谢谢

0 个答案:

没有答案