【问题标题】:T-SQL not executing 2nd part of WHERE clause SSRST-SQL 未执行 WHERE 子句 SSRS 的第二部分
【发布时间】:2012-08-31 11:05:02
【问题描述】:

我有一个从存储过程运行的 SSRS 报告。我有 2 个必须选择的参数。 My first parameter works perfectly, but when the 2nd parameter is chosen (Rep) it gets ignored by the report and returns all the Reps.

@Town Varchar(100)
,@Rep Varchar(100)

    select 
    a.Customer
    ,a.CustName
    ,a.Rep
    ,a.Town
    ,a.Qty
    ,a.SalesType
    ,b.Qty1
    ,c.Qty2
    ......
    from #1 a
    left join #2 b
    on a.Rep = b.Rep
    and a.Town = b.Town
    and a.Customer = b.Customer
    and a.SalesType = b.SalesType
    left join #3 c
    ..........
    WHERE ('ALL' IN (@Town))    OR     (a.Town IN (@Town)) 
    and ('ALL' IN (@Rep))    OR     (a.Rep IN (@Rep))

【问题讨论】:

    标签: tsql reporting-services where-clause


    【解决方案1】:

    在这里猜测,但我假设您希望将 @Town@Rep 的子句作为一个组进行评估。这样做:

    WHERE ('ALL' IN (@Town)    OR     a.Town IN (@Town)) 
    and ('ALL' IN (@Rep)    OR     a.Rep IN (@Rep))
    

    正如你所拥有的,由于每个子句都是独立的,你会得到短路行为。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-28
      • 1970-01-01
      • 1970-01-01
      • 2012-12-23
      • 1970-01-01
      相关资源
      最近更新 更多