Solved

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

Posted on 2012-03-28
8
2,059 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
  • 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
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 500 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Introduction Earlier I wrote an article about the new lookup functions (http://www.experts-exchange.com/A_3433.html) that ship with SQL Server 2008 R2.  In this article I’m going to show you another new feature of SSRS 2008 R2, this time in the vis…
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

839 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