Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2012-03-28
8
Medium Priority
?
2,322 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 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Hi, I have heard from my friends that it’s not possible to create Label Printing report using SSRS. I am amazed after hearing this words not possible in SSRS. I googled lot and found that it is possible to some of people know about the Report Bui…
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

824 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