2016-08-22 31 views
0

我有以下在SSMS中正常工作的查詢,它在SSRS報告生成器3.0的查詢設計器中工作。它需要三個參數其中之一(@年)是從今天開始多少年你想要的結果。我已將@year指定爲-1,-2,-3,-4或-5。但是,當我運行這份報告時,無論我選擇什麼樣的價值,它只會返回今年1月份的結果(見圖)。當我將@year表達式添加到報表時,它顯示正在向查詢傳遞正確的值。有什麼我做錯了嗎?從SSRS查詢設計器在SSRS運行報表 Results from Running the Report in SSRSSSRS - 爲什麼我的報告只會從當年返回日期?

結果

declare @complete varchar(1) = 'y', 
@supplier_id Nvarchar(max) = 1, 
@year int = -1 


select p21_view_address.name [Supplier Name], p21_view_po_hdr.supplier_id [Supplier ID], p21_view_po_line.po_no [PO #],p21_view_po_hdr.location_id [PO Location ID], line_no [PO Line #] 
    , p21_view_inv_mast.item_id [Item ID], p21_view_inv_mast.item_desc [item_desc], p21_view_po_line.date_created [PO Date Created], unit_quantity [Qty Ordered] 
    , qty_received [Qty Received] , convert(varchar(10), cast(p21_view_po_line.date_due as date), 101) [Expected Date], coalesce(convert(varchar(10), cast(p21_view_po_line.received_date as date), 101), 'Not Received Yet') [Receipt Date], p21_view_po_hdr.approved [PO Approved?], [pi].average_lead_time [Lead Time] 
    , convert(varchar(10), cast(po_hdr_ud.purchase_order_confirmation as date), 101) [Confirmation Date], convert(varchar(10), cast(p21_view_po_line.required_date as date), 101) [Required Date] from p21_view_po_line 
INNER JOIN p21_view_po_hdr ON p21_view_po_line.po_no = p21_view_po_hdr.po_no 
join p21_view_inv_mast on p21_view_inv_mast.inv_mast_uid = p21_view_po_line.inv_mast_uid 
join p21_view_supplier_purchasing_info [pi] on p21_view_po_line.inv_mast_uid = [pi].inv_mast_uid and p21_view_po_hdr.location_id = [pi].location_id and p21_view_po_hdr.supplier_id = [pi].supplier_id 
join p21_view_address on p21_view_po_hdr.supplier_id = p21_view_address.id 
join po_hdr_ud on p21_view_po_line.po_no = po_hdr_ud.po_no 
where p21_view_po_line.cancel_flag = 'N' and p21_view_po_line.delete_flag = 'N' and p21_view_po_line.complete = @complete and (@supplier_id = 1 or p21_view_po_hdr.supplier_id in (@supplier_id)) 
and p21_view_po_line.date_created > DATEADD(year, @year, GETDATE()) 
order by p21_view_po_line.date_created asc 

結果 enter image description here

+0

以前的日期可能在第2頁或更晚? – newGuy

回答

1

我不知道爲什麼會這樣,但我通過刪除固定問題排序我在桌上的Tablix屬性。我在PO_Date_created上設置了它,但我也在我的SQL代碼中通過PO_Date_created進行了排序。當我從表中刪除Tablix排序屬性然後結果正確返回。 enter image description here

相關問題