我有一个 SSRS 报告,其中一个参数可以取 3 个值。选择查询在所有情况下都是相同的,但 where 子句需要根据参数值检查不同的日期字段。这可能在同一个查询中吗?
询问:
SELECT OrdNO, OrdType, customer, SalesRep, FundDate, DisbursementDate, Branch, SalesPrice
FROM Orders
-- Case @ReportType=1, use FundDate
where (FundDate >= @FromDate and FundDate <= @ToDate)
-- Case @ReportType=2, use DisbursmentDate
Where (DisbursementDate >= @FromDate and DisbursementDate <= @ToDate)
-- Case @ReportType=3, use both dates
where (FundDate >= @FromDate and FundDate <= @ToDate) or (DisbursementDate >= @FromDate and DisbursementDate <= @ToDate)