I have two reports which share one stored procedure as a dataset source and are almost identical except of filter clausule. I've created an inner report parameter and what to set a filter according to this param.
I've tried:
...data
WHERE
CASE WHEN @ReportFilter = 1 THEN apd.[Date] BETWEEN @DateFrom AND @DateTo
WHEN @ReportFilter = 2 THEN pd.[Date] BETWEEN @DateFrom AND @DateTo
END
Just use your case expression to return a single date value and then check if that value is between @DateFrom and @DateTo. I also simplified the case expression a bit.
WHERE
CASE @ReportFilter
WHEN 1 THEN apd.[Date]
WHEN 2 THEN pd.[Date]
END
BETWEEN @DateFrom AND @DateTo
But be careful with BETWEEN, it can cause some challenges:
Try
(1 = CASE WHEN @ReportFilter = 1 and apd.[Date] BETWEEN @DateFrom AND @DateTo then 1
WHEN @ReportFilter = 2 and pd.[Date] BETWEEN @DateFrom AND @DateTo then 1
END)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.