添加where子句后,SSRS SQL查询显示错误

时间:2014-07-21 01:11:49

标签: sql-server reporting-services

我有一个完整的查询,可以在SSRS中正确显示,但是,当我添加这个where子句时,我收到错误

  

数据集' dataset1'的查询执行失败。 (rsErrorExecutingCommand)

这是我添加的WHERE子句:

where 
    (itemNo = @ItemNo or @ItemNo is NULL) 
    and (JobNo in (@JobNo) or @JobNo is NULL) 
    and (customerNo = @CustomerNo or @CustomerNo is NULL) 
    and (LotNo in (@LotNo) or @LotNo is NULL)
    and (Station = @Station or @Station is NULL) 
    and ((DateTimeStamp between @startDate and  @endDate) or (@startDate is null and @endDate is Null))

你们有任何想法我在这里做了什么语法错误吗?

1 个答案:

答案 0 :(得分:0)

我添加String后代码正常工作。下面是我做的,它的工作正常。 这是因为,我注意到值不是Null,而是空字符串,这就是我的代码不起作用的原因。

(itemNo = @ItemNo or @ItemNo is NULL or @ItemNo = '') 
and(JobNo = @JobNo or @JobNo is NULL or @JobNo = '')
and(customerNo = @CustomerNo or @CustomerNo is NULL or @CustomerNo = '') 
and (LotNo = @LotNo or @LotNo is Null or @LotNo = '')
and (Station = @Station or @Station is NULL or Station = '') 
and ((DateTimeStamp between @startDate and @endDate) or (@startDate is null and @endDate is Null))