SSRS CASE根据参数选择然后传递Select语句

SSRS CASE based on parameter selection to then pass Select statement

我有一个 SSRS 报告,其中的参数有 3 个选项

  1. 客户 = 全部
  2. 客户 = A(超过 1 个客户)
  3. 客户 = 全部 - A

基于 selection 我希望 SQL 成为

Case 2
 Select * from customers where customer in (A)
Case 3
 Select * from customers where customer not in (A)
Else
 Select * from customers

我的参数是: [![Select * from customers where customer not in (A)][1]][1]
[1]: https://i.stack.imgur.com/mWZoU.png

我的 select 陈述目前是:

    select t.Docket, t.TranType, Convert(Date,t.Despatchdatetime) as DespatchDate, t.Depot, t.Plant, t.Product, p.ProductName, t.Gross, t.Net, t.Tare, t.Vehicle, t.Rego, p.ProductName + ' ' + t.Docket as TEXT, T.Vehicle + ' ' + T.Rego as [Field Assignment], t.Customer + ' ' + t.CustomerName as Customer
    from trans t, product p
    where t.depot in (@Depot)
    and t.plant in (@Plant)
    and t.DespatchDateTime >= (@DespatchFrom) and t.despatchDateTime <= (@DespatchTo)
    and p.Product = t.product
    and t.cancelleddocket = '0'
    and t.trantype <> 'DIV'
**  and t.customer [Depending on parameter selection]
    Order by t.plant, t.despatchdatetime,t.docket

但我似乎无法正确表述:

SELECT
    CASE
        WHEN Parameters!Customers.Value='Exclude' then 
                        (    select t.Docket, t.TranType, Convert(Date,t.Despatchdatetime) as DespatchDate, t.Depot, t.Plant, t.Product, p.ProductName, t.Gross, t.Net, t.Tare, t.Vehicle, t.Rego, p.ProductName + ' ' + t.Docket as TEXT, T.Vehicle + ' ' + T.Rego as [Field Assignment], t.Customer + ' ' + t.CustomerName as Customer
                from trans t, product p
                where t.depot in (@Depot)
                and t.plant in (@Plant)
                and t.DespatchDateTime >= (@DespatchFrom) and t.despatchDateTime <= (@DespatchTo)
                and p.Product = t.product
                and t.cancelleddocket = '0'
                and t.trantype <> 'DIV'
                and t.customer not in ('123','456')
                Order by t.plant, t.despatchdatetime,t.docket )
            
        WHEN Parameters!Customers.Value='ABL' then 
                        (select t.Docket, t.TranType, Convert(Date,t.Despatchdatetime) as DespatchDate, t.Depot, t.Plant, t.Product, p.ProductName, t.Gross, t.Net, t.Tare, t.Vehicle, t.Rego, p.ProductName + ' ' + t.Docket as TEXT, T.Vehicle + ' ' + T.Rego as [Field Assignment], t.Customer + ' ' + t.CustomerName as Customer
                from trans t, product p
                where t.depot in (@Depot)
                and t.plant in (@Plant)
                and t.DespatchDateTime >= (@DespatchFrom) and t.despatchDateTime <= (@DespatchTo)
                and p.Product = t.product
                and t.cancelleddocket = '0'
                and t.trantype <> 'DIV'
                and t.customer in ('123','456')
                Order by t.plant, t.despatchdatetime,t.docket )
        
                ELSE 
                        (select t.Docket, t.TranType, Convert(Date,t.Despatchdatetime) as DespatchDate, t.Depot, t.Plant, t.Product, p.ProductName, t.Gross, t.Net, t.Tare, t.Vehicle, t.Rego, p.ProductName + ' ' + t.Docket as TEXT, T.Vehicle + ' ' + T.Rego as [Field Assignment], t.Customer + ' ' + t.CustomerName as Customer
                from trans t, product p
                where t.depot in (@Depot)
                and t.plant in (@Plant)
                and t.DespatchDateTime >= (@DespatchFrom) and t.despatchDateTime <= (@DespatchTo)
                and p.Product = t.product
                and t.cancelleddocket = '0'
                and t.trantype <> 'DIV'
                Order by t.plant, t.despatchdatetime,t.docket )
END
  select t.Docket, t.TranType, Convert(Date,t.Despatchdatetime) as DespatchDate, t.Depot, t.Plant, t.Product, p.ProductName, t.Gross, t.Net, t.Tare, t.Vehicle, t.Rego, p.ProductName + ' ' + t.Docket as TEXT, T.Vehicle + ' ' + T.Rego as [Field Assignment], t.Customer + ' ' + t.CustomerName as Customer
                from trans t
                join product p ON p.Product = t.product
                where t.depot in (@Depot)
                and t.plant in (@Plant)
                and t.DespatchDateTime >= (@DespatchFrom) and t.despatchDateTime <= (@DespatchTo) 
                and t.cancelleddocket = '0'
                and t.trantype <> 'DIV'
                and (( @Customers = 'Exclude' and t.customer not in ('123','456') )
                    OR(@Customers='ABL' AND t.customer in ('123','456') )
                    OR @Customers='ALL'
                    )
                Order by t.plant, t.despatchdatetime,t.docket )