Report Builder 可选和强制参数
Report Builder optional and obligatory parameters
我的实时查询报告有问题。在我的报告中,我有 5 个参数允许选择日期范围 @DateFrom
和 @DateTo
以及 3 个参数应该允许 select 特定属性:
@salesid, @batch, @serial
我想强制设置日期范围参数,这没有任何问题,但最后 3 个参数:@salesid
、@batch
、@serial
应该是可选的。
但它们没有按预期工作。最后 3 个参数应该让您输入可以用作过滤器的值。但是当我选择日期和其中一个参数时,我得到了查询的整个值而不是 selected 值。
在参数属性中,我选择了 "Allow blank value ("“)”选项,以防万一我将默认值定义为空白。
这就是我查询中的条件:
where
st.custaccount <> 'number%'
and datepart(year,st.CREATEDDATETIME) >= 2012
and (ita.VENDORCODE like'producer1' or ita.vendorcode like 'producer2')
and st.createddatetime >= @FromDate
and st.createddatetime <= @ToDate
or (st.salesid = @salesid or @salesid is null)
or (itd.INVENTBATCHID = @batch or @batch is null)
or (itd.INVENTSERIALID = @serial or @serial is null)
理论上它应该可以工作但是...好吧但在实践中它不是。
如何设置条件才能达到预期的效果?到目前为止我找不到任何有用的东西。如果你们知道有用的东西请给我一些线索。
您需要将最后 3 个 or
语句更改为 and
语句。
目前,您的查询实质上是在检查符合您条件的数据项 或 最后三个参数中的任何一个是matched/null。这意味着即使您的数据不是日期范围等,它仍然会被返回:
where st.custaccount <> 'number%'
and st.CREATEDDATETIME >= '20120101' -- Try not to use functions in your WHERE clause, as this stops indexes from working, making your query less efficient.
and ita.VENDORCODE in('producer1', 'producer2') -- IN has the same effect.
and st.createddatetime between @FromDate and @ToDate -- BETWEEN is an inclusive date range. Equivalent to >= and <=
and (st.salesid = @salesid
or @salesid is null
)
and (itd.INVENTBATCHID = @batch
or @batch is null
)
and (itd.INVENTSERIALID = @serial
or @serial is null
)
我的实时查询报告有问题。在我的报告中,我有 5 个参数允许选择日期范围 @DateFrom
和 @DateTo
以及 3 个参数应该允许 select 特定属性:
@salesid, @batch, @serial
我想强制设置日期范围参数,这没有任何问题,但最后 3 个参数:@salesid
、@batch
、@serial
应该是可选的。
但它们没有按预期工作。最后 3 个参数应该让您输入可以用作过滤器的值。但是当我选择日期和其中一个参数时,我得到了查询的整个值而不是 selected 值。
在参数属性中,我选择了 "Allow blank value ("“)”选项,以防万一我将默认值定义为空白。
这就是我查询中的条件:
where
st.custaccount <> 'number%'
and datepart(year,st.CREATEDDATETIME) >= 2012
and (ita.VENDORCODE like'producer1' or ita.vendorcode like 'producer2')
and st.createddatetime >= @FromDate
and st.createddatetime <= @ToDate
or (st.salesid = @salesid or @salesid is null)
or (itd.INVENTBATCHID = @batch or @batch is null)
or (itd.INVENTSERIALID = @serial or @serial is null)
理论上它应该可以工作但是...好吧但在实践中它不是。
如何设置条件才能达到预期的效果?到目前为止我找不到任何有用的东西。如果你们知道有用的东西请给我一些线索。
您需要将最后 3 个 or
语句更改为 and
语句。
目前,您的查询实质上是在检查符合您条件的数据项 或 最后三个参数中的任何一个是matched/null。这意味着即使您的数据不是日期范围等,它仍然会被返回:
where st.custaccount <> 'number%'
and st.CREATEDDATETIME >= '20120101' -- Try not to use functions in your WHERE clause, as this stops indexes from working, making your query less efficient.
and ita.VENDORCODE in('producer1', 'producer2') -- IN has the same effect.
and st.createddatetime between @FromDate and @ToDate -- BETWEEN is an inclusive date range. Equivalent to >= and <=
and (st.salesid = @salesid
or @salesid is null
)
and (itd.INVENTBATCHID = @batch
or @batch is null
)
and (itd.INVENTSERIALID = @serial
or @serial is null
)