我正在制作一个 rdl 报告,并且我有三个复选框,如果选中,则需要更改我的 WHERE 语句。如果未选中,则结果应仅按日期范围匹配。如果选中一个或多个,则需要返回与变量对应的字符串匹配的字段。
WHERE
(EffectiveDate BETWEEN @StartDate AND @EndDate)
AND (((@IncludeSEWPrefix = 1 AND PrefixId = 'SEW') OR @IncludeSEWPrefix = 0)
AND ((@IncludePAWPrefix = 1 AND PrefixId = 'PAW') OR @IncludePAWPrefix = 0)
AND ((@IncludeRPLPrefix = 1 AND PrefixId = 'RPL') OR @IncludeRPLPrefix = 0))
到目前为止,我的代码在没有选中和选中一个时有效,但在选中多个复选框时不返回任何内容。所以为了尝试解决这个问题,我将代码更改为
WHERE
(EffectiveDate BETWEEN @StartDate AND @EndDate)
AND ((((@IncludeSEWPrefix = 1 AND PrefixId = 'SEW') OR @IncludeSEWPrefix = 0)
OR ((@IncludePAWPrefix = 1 AND PrefixId = 'PAW') OR @IncludePAWPrefix = 0)
OR ((@IncludeRPLPrefix = 1 AND PrefixId = 'RPL') OR @IncludeRPLPrefix = 0)))
这导致无论选择什么都会返回所有行。有人可以告诉我哪里出错了吗?