Solved

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

Posted on 2012-03-28
8
1,968 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
 
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Visual Studio 2008 book recommendation 6 31
SQL Help joining two tables 7 34
SQL Select Prior Ship Date Data 2 31
SQl query 19 14
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…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

760 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now