[英]SSRS CASE based on parameter selection to then pass Select statement
我有一個帶有 3 個選項的參數的 SSRS 報告
根據選擇,我希望 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 語句目前是:
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 )
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.