如何添加参数来报告

时间:2017-08-14 09:57:12

标签: sql sql-server reporting-services reportbuilder3.0

select distinct sotr_sys_no
            , SODETS_VINYL_COLOUR
            , SODETS_MDF_COLOUR
            , SOTR_PROMISED_DATE
            , DATEDIFF(dd,getdate(),sotr_promised_date) as DueDays
            , AEXTRA_5_SHORT_NAME
            , AEXTRA_5_VINYL_PARTCODE
            , CASE WHEN SODETS_MDF_COLOUR > '0' THEN AltMDFCode ELSE  AEXTRA_5_MDF_PARTCODE END AS AEXTRA_5_MDF_PARTCODE
            , ISNULL(Vinylqty,0) As VinylQty
            , ISNULL(MDFqty,0) as MDFQty
            , Vinyldue
            , MDFdue
            , WO.WOOutstanding
from Defactouser.F_SO_Transaction WITH (NOLOCK)
    inner join defactouser.F_SO_Transaction_Details WITH (NOLOCK) 
                on sotr_sys_no = sotd_head_no

    inner join defactouser.F_SO_Transaction_Details_Extra WITH (NOLOCK) 
                on SOTD_SYS_NO = SODETS_LINK

    left outer join (
                        select distinct AEXTRA_5_CODE as AltMDFKey
                                , AEXTRA_5_MDF_PARTCODE AS AltMDFCode 
                        from DeFactoUser.F_AD_Extra_5 WITH (NOLOCK) 
                    )   as AltMDF 
                        on SODETS_MDF_COLOUR = AltMDF.AltMDFKey

    left outer join defactouser.F_AD_Extra_5 WITH (NOLOCK) 
                on SODETS_VINYL_COLOUR = [AEXTRA_5_CODE]

    inner join defactouser.F_ST_Products WITH (NOLOCK) 
                on sotd_strc_code = strc_code 

    left Outer join (
                            SELECT Product_Code As VinylStockCode, sum(Physical_Qty_Units) as Vinylqty  FROM DBO.DFBI_Stock_Physical WITH (NOLOCK)
                            WHERE Warehouse = 'DOORS' and LEFT(product_code ,3) = 'vfl'
                            Group By Product_Code
                            HAVING SUM(Physical_Qty_Units) >0
                    )       VinylStock 
                            on AEXTRA_5_VINYL_PARTCODE = VinylStock.VinylStockCode

    left outer join (       
                            SELECT Product_Code As MDFStockCode, sum(Physical_Qty_Units) as MDFqty  FROM DBO.DFBI_Stock_Physical WITH (NOLOCK)
                            WHERE Warehouse = 'PANELS' and LEFT(product_code ,3) = 'MDF'
                            Group By Product_Code
                            HAVING SUM(Physical_Qty_Units) >0
                    )       MDFStock  
                            on CASE WHEN SODETS_MDF_COLOUR > '0' THEN AltMDF.AltMDFCode ELSE  AEXTRA_5_MDF_PARTCODE END = MDFStock.MDFStockCode

    left Outer JOin (select stex_strc_code as VinylStex , sum(STEX_QTY_UNITS) as Qty, MIN(stex_promised_date) as Vinyldue
                            from defactouser.F_ST_Transaction_Expediting 
                            where left(stex_strc_code ,3) = 'vfl'
                                    and stex_type = 'pop+'
                            group By STEX_STRC_CODE
                    )       VinylStockIn 
                            on AEXTRA_5_VINYL_PARTCODE = VinylStex

    left Outer Join (
                        select stex_strc_code as MDFStex , sum(STEX_QTY_UNITS) as Qty, MIN(stex_promised_date) as MDFdue
                        from defactouser.F_ST_Transaction_Expediting 
                        where left(stex_strc_code ,3) = 'mdf'
                                and stex_type = 'pop+'
                        group By STEX_STRC_CODE

                    ) MDFStockIn on CASE WHEN SODETS_MDF_COLOUR > '0' THEN AltMDF.AltMDFCode ELSE  AEXTRA_5_MDF_PARTCODE END = MDFStex

    LEFT OUTER JOIN (
                        select SOTD_HEAD_NO, SODETS_VINYL_COLOUR as WOVinyl,  SUM(BMTD_QTY_OUTSTANDING) as WOOutstanding from defactouser.f_bm_transactions_details
                        inner join defactouser.F_SO_Transaction_Details on BMTD_ORDER_LINK_NUMBER = SOTD_SYS_NO
                        inner join defactouser.F_SO_Transaction_Details_Extra on BMTD_ORDER_LINK_NUMBER = SODETS_LINK
                        where bmtd_type = 1 and bmtd_bmtr_type = 0 and bmtd_stwh_code in ('doors', 'shef trans') and SOTD_STATUS <99
                        Group by SOTD_HEAD_NO, SODETS_VINYL_COLOUR
                    ) WO
                    on sotr_sys_no = WO.SOTD_HEAD_NO AND SODETS_VINYL_COLOUR = WO.WOVinyl


    where (SOTD_QTY_UNITS_OUTSTANDING > 0 
            and SOTR_TYPE = 10 
            and SOTD_STWH_CODE IN ('doors' , 'hpp shef')
            and left(sotd_strc_code ,5) <> 'drill'
            and SOTR_CUST_CODE <>'hpp'
            and STRC_ANAL1 = '1027'
            and ISNULL(VinylQty,0) <10
            and DATEDIFF(dd,getdate(),sotr_promised_date) <5

            )

            or

            (SOTD_QTY_UNITS_OUTSTANDING > 0 
            and SOTR_TYPE = 10 
            and SOTD_STWH_CODE IN ('doors' , 'hpp shef')
            and left(sotd_strc_code ,5) <> 'drill'
            and SOTR_CUST_CODE <>'hpp'
            and STRC_ANAL1 = '1027'
            and ISNULL(MDFQty,0) <4
            and DATEDIFF(dd,getdate(),sotr_promised_date) <5

            )

Order By MDFQty, AEXTRA_5_MDF_PARTCODE

目前,此查询会生成一个报表,该报表会返回一个表格,其中包含将在未来5天内到达的产品。如何在报告中添加一个参数,以便按原样显示结果,然后还可以显示每次产品到期的产品报告。我正在使用Report Builder 3.0,并尝试添加参数但无法获得所需的结果。 这可以在不编辑查询的情况下完成,只需在报表生成器中完成吗?

1 个答案:

答案 0 :(得分:0)

更改WHERE子句并将< 5替换为< @Days。假设查询不是存储过程并直接在数据集查询中,则SSRS会自动将@Days参数添加到报表中。