SSRS传递多个参数。给定可用值。是否可以使用LIKE运算符

时间:2017-05-24 19:02:44

标签: sql reporting-services ssrs-2008

我是SSRS报告的新手。我有一个存储过程来根据salesman参数提取已开票少于14.9%GP的所有项目。

ALTER PROCEDURE [dbo].[sp_Lessthan15GPAlert]
-- Add the parameters for the stored procedure here
 @salesrep varchar(100)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

SELECT  distinct
    oh.CustomerCode
    , c.CustomerName
    , ohl.ProductCode
    , ohl.ProductDescription1
    , ohl.ProductDescription2
    , oh.InvoiceNumber
    , CONVERT(VARCHAR(10), oh.InvoiceDate,126) InvoiceDate
    , ((ohl.NetPrice-ohl.AccountingCost)/ohl.NetPrice) * 100 AS GP
    , OHL.PriceSourceCode
    , OH.SellingWarehouseNumber
    , s.description
FROM OrderHistory oh 
    inner join orderhistoryline ohl on oh.CompanyID = ohl.CompanyID and oh.OrderNumber = ohl.OrderNumber
    inner join Customer c on c.CompanyID = oh.companyid and c.customercode = oh.CustomerCode
    inner join salesman s on s.companyid = c.CompanyID and s.SalesmanID = c.SalesRepOne
WHERE oh.CompanyID = '002' 
    and oh.InvoiceDate = CONVERT(varchar(10),dateadd(d,-4,GetDate()),126)
    AND ((ohl.NetPrice - ohl.AccountingCost)/ohl.NetPrice) * 100 < 14.9 
    and ohl.NetPrice <> 0.00
    AND OHL.PRICESOURCECODE NOT LIKE 'M%'
    and s.description like @salesrep
    AND COALESCE(OHL.ShippedQuantity,0) <> 0
END

salesman表中的description列包含样本数据

R02 702 SMITH, JOHN TSR
R07 707 FRANKLIN, ROB TSR
R04 704 SCOTT, KEVIN TSR
R04 704 PAUL, KEITH RSM
R02 702 JOSEPH, MARY TSR
R04 704 CRIPPS, ROBERT TSR

Keith Paul管理着702和704两个地点。

我已为参数@salesrep设置了可用值,如下所示

| Label | Value

%SMITH%JOHN% | %SMITH%JOHN% 

%FRANKLIN%ROB% | %FRANKLIN%ROB%

%SCOTT%KEVIN% | %SCOTT%KEVIN%

%PAUL%KEITH% | %PAUL%KEITH% 

% | %  

L702 | R02%702%

L707 | R07%707%

L704 | R04%704%

现在,我可以为每个销售人员和每个地区运行报告,但我也想为每个RSM(区域销售经理)运行。假设我想在Keith Paul的指导下运行一切。如何在参数的可用值中再添加一个,例如

标签|值

基斯保罗| R02%702%,R04%704%

所以我会得到702和704的结果。我怎样才能做到这一点?

R02 702 SMITH, JOHN TSR
R04 704 SCOTT, KEVIN TSR
R04 704 PAUL, KEITH RSM
R02 702 JOSEPH, MARY TSR
R04 704 CRIPPS, ROBERT TSR

编辑:我在where子句中使用了case语句,并在可用值中添加了Keith-Western并且它有效。如果通过更改查询有不同的解决方案,请告诉我。

WHERE oh.CompanyID = '002' 
and oh.InvoiceDate = CONVERT(varchar(10),dateadd(d,-4,GetDate()),126)
AND ((ohl.NetPrice - ohl.AccountingCost)/ohl.NetPrice) * 100 < 14.9 
and ohl.NetPrice <> 0.00
AND OHL.PRICESOURCECODE NOT LIKE 'M%'
and (CASE @salesrep WHEN 'Keith-Western' then s.description end like 'R02%702%'
        or
CASE @salesrep WHEN 'Keith-Western' then s.description end like 'R04%704%'
        or s.description like @salesrep)
AND COALESCE(OHL.ShippedQuantity,0) <> 0

0 个答案:

没有答案