Solved

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

Posted on 2012-03-28
8
2,095 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
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

Free eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL - format decimal in a string 5 49
Add a step to a system backup job 6 30
SSRS Deployment problem 5 90
Parse this column 6 34
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…
In this article I will describe the Copy Database Wizard 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.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

680 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