繁体   English   中英

报表生成器的可选参数

[英]Report Builder optional and obligatory parameters

我的实时查询报告有问题。 在我的报告中,我有5个参数可以选择日期范围@DateFrom@DateTo还有3个参数可以选择特定的属性:

@salesid, @batch, @serial

我想使日期范围参数成为强制性,并且可以正常工作,但最后3个参数: @salesid@batch@serial应该是可选的。

但是它们无法正常工作。 最后3个参数应让您键入可用作过滤器的值。 但是,当我选择日期和那些参数之一时,我将获取查询的整个值而不是所选值。

在参数属性中,我选择了“允许空白值(“”)“选项,以防万一我将默认值定义为空白。

这就是查询条件的样子:

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语句。

目前,您的查询实际上是在检查是否符合您的条件的数据项, 或者最后三个参数中的任何一个是否匹配/为空。 这意味着即使您的数据不是日期范围等,它仍将被返回:

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
        )

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM