2017-08-14 137 views
-3
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

尝试先使用google,如下所示:https://docs.microsoft.com/en-us/sql/reporting-services/tutorial-add-a-parameter-to-your-report-report-builder –

+0

@StanislovasKalašnikovas谢谢,我在阅读后到了某处,但下面的答案是完美的。 – Neal1581

+0

请不要破坏你的帖子。一旦你发布了一个问题,你已经将内容授权给了Stack Overflow社区(在CC-by-SA许可下)。如果您想取消关联此帐户与您的帐户关联,请参阅[解除请求的正确途径是什么?](http://meta.stackoverflow.com/questions/323395/what-is-the-proper-route-换一个 - 解离 - 请求)。 – Bugs

回答

0

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

+0

谢谢你,Alan,感谢你发布。现在就开始工作了。 – Neal1581

相关问题