我有以下查询在SSMS中正常工作,它可以在SSRS报表生成器3.0的查询设计器中使用。它需要三个参数,其中一个(@year)是从今天起多少年后你想要的结果。我已经为@year指定为-1,-2,-3,-4或-5。但是当我运行报告时,无论我今年选择什么价值,它都只会返回当年1月份的结果(见图)。当我将@year表达式添加到报表时,它会显示正在传递给查询的正确值。有什么我做错了吗?
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