2017-08-14 86 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