0

我有一个从存储过程运行的 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))
4

1 回答 1

5

在这里猜测,但我假设您希望每个子句 for@Town@Repbe 作为一个组进行评估。为此:

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

正如您所拥有的,由于每个子句都是独立的,您将获得短路行为。

于 2012-08-31T11:08:54.647 回答