Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

SSRS Report - Multi-Value Parameters - Allow Blank Values Checked

Posted on 2012-03-28
8
Medium Priority
?
2,249 Views
Last Modified: 2012-06-27
I have a question regarding a SSRS report that uses Multi Value Parameters (@Country, @City) with the “allow blank values” option checked.   Since the report is to show all customers, but not all of the customers will have an “Active” “Preferred” address type, some customers will not have any address information in the report.

When the user checks the parameter that refers to a blank ‘’ value and runs the SSRS report, no data appears.  If the user selects uses the “Select All” option, and everything is selected, only the records with a state appear, not the blank ‘’ state records.   I believe it may have something to do with the function “nl_fn_MultiVal_String” used in the Stored Procedure, but I am not sure.

1)       If it is the function “nl_fn_MultiVal_String”, how can the function be edited/updated to accept and return the blank ‘’ values to the mulit-value parameter string?
2)       If the “IF @TrimSpace = 1 Set @Val = LTRIM(RTRIM(@Val))” is the issue in the function, what problems might it create if it is eliminated?
 
SSRS Report uses a Stored Procedure,“nl_p_Cust_AddrInfo”.  The Stored Procedure references the below View (“nl_v_ActiveAddrInfo”):
SELECT
Customer.CustID
(COALESCE,Address. Type,’’) AS ADDR_TYPE
(COALESCE,Address.Status,’’) AS ADDR_STATUS
(COALESCE,Address.City,’’) AS ADDR_CITY
(COALESCE,Address.State,’’) AS ADDR_STATE
(COALESCE,Address.Country,’’) AS ADDR_COUNTRY
FROM Customer
LEFT OUTER JOIN Address
    ON Customer.CustID = Address.CustID
    AND Address.Status = ‘Active’

The above view, “nl_v_ActiveAddrInfo” is used in the below Stored Procedure “nl_p_Cust_AddrInfo”:
  @Country  AS varchar(max)
,@City  AS varchar(max)
SELECT
Customer.CustID
,Customer.Name
,nl_v_ActiveAddrInfo.ADDR_TYPE
, nl_v_ActiveAddrInfo.ADDR_CITY
, nl_v_ActiveAddrInfo.ADDR_STATE
, nl_v_ActiveAddrInfo.ADDR_COUNTRY
FROM Customer
LEFT OUTER JOIN  nl_v_ActiveAddrInfo
   ON   Customer.CustID = nl_v_ActiveAddrInfo.CustID
   AND Customer.Preferred_Addr = nl_v_ActiveAddrInfo.ADDR_TYPE
WHERE nl_v_ActiveAddrInfo.ADDR_COUNTRY IN (SELECT Val FROM nl_fn_MultiVal_String(@Country,’,’,1))
AND  nl_v_ActiveAddrInfo.ADDR_CITY IN (SELECT Val FROM nl_fn_MultiVal_String(@City,’,’,1))

The Table –Valued Function “nl_fn_MultiVal_String” is used in the above Store Procedure:
   @String VARCHAR(max), /* input string */
   @Delimeter char(1),   /* delimiter */
   @TrimSpace bit )      /* kill whitespace? */
RETURNS @Table TABLE ( [Val] VARCHAR(4000) )
AS
BEGIN
    DECLARE @Val    VARCHAR(4000)
    WHILE LEN(@String) > 0
    BEGIN
        SET @Val    = LEFT(@String,
             ISNULL(NULLIF(CHARINDEX(@Delimeter, @String) - 1, -1),
             LEN(@String)))
        SET @String = SUBSTRING(@String,
             ISNULL(NULLIF(CHARINDEX(@Delimeter, @String), 0),
             LEN(@String)) + 1, LEN(@String))
  IF @TrimSpace = 1 Set @Val = LTRIM(RTRIM(@Val))
    INSERT INTO @Table ( [Val] )
        VALUES ( @Val )
    END
    RETURN
0
Comment
Question by:nulad
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 

Author Comment

by:nulad
ID: 37776879
Just an update.......

I changed the one line in the Stored Procedure Where clause from a 1 to a 0 so the @TrimSpace would not =1:

AND nl_v_ActiveAddrInfo.ADDR_CITY IN (SELECT Val FROM nl_fn_MultiVal_String(@City,’,’,0))

The report still does not pull the Customers with a blank/empty '' nl_v_ActiveAddrInfo.ADDR_STATE field.
0
 
LVL 9

Expert Comment

by:rajeevnandanmishra
ID: 37776898
Hi,
Try changing the where clause of your view as follows:
------
WHERE nl_v_ActiveAddrInfo.ADDR_COUNTRY IN (case when @Country = '' then (@Country)
      else (SELECT Val FROM nl_fn_MultiVal_String(@Country,’,’,1)) end)
AND  nl_v_ActiveAddrInfo.ADDR_CITY IN (case when @City = '' then (@City) else (SELECT Val FROM nl_fn_MultiVal_String(@City,’,’,1)) end)

-----
0
 

Author Comment

by:nulad
ID: 37777133
rajeevnandanmishra, thank you for your response.  Tried changing the stored procedure to your suggestion.  If the user only selects one of the parameter's options it works fine.  If more than one parameter option is selected (multi-values) it creates an error message "subquery returned more than one value.  This is not permitted when the subquery follows =, <, <=, >, >=, or when the subquery is used as an expression. "

This is being used in the SSRS report with a parameter with the "Allow multiple values" and "Allow blank value("")" checked.
0
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 
LVL 9

Expert Comment

by:rajeevnandanmishra
ID: 37777228
Ok. Got it. It seems that you are passing the "Blank" and "Non-Blank" values together in the @Country/@City.

How you are passing the parameter value? Can you place an example of data in @Country or @City? I need to see that how the "BLANK" value is passed. Accordingly we can check the Function.
0
 

Author Comment

by:nulad
ID: 37777790
It is actually @State.  See attached file for screen shots.
0
 

Author Comment

by:nulad
ID: 37777881
Attached is the file with the screen shots.
SSRS-MultiValue-Question02012032.pdf
0
 
LVL 9

Accepted Solution

by:
rajeevnandanmishra earned 2000 total points
ID: 37778704
Hello,
I tried to replicate your situation and found the same result as of you.
Actually, in case of "SELECT ALL", SSRS is not passing a blank and in case of selecting the "Blank", it is just passing the blank ('') that is not used by our procedure.
So we need to make a twist here.
I have mentioned few steps in the attached document. If something is still not working then let us know.

2012032901095312.doc
0
 

Author Closing Comment

by:nulad
ID: 37778791
Thank you so much for your help.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question