简体   繁体   中英

How to get multiple values along with null values in sql server and ssrs

I am working on this SSRS report, where user is asking me to create a report that has three parameters: Term, Student Status, and Admission Offer.

Description: There are following distinct admission offers:
Declined-Program cost Declined-Other Declined-Scheduling/Timing Accepted Declined-Enrolling at another school Declined-Program fit/Educational needs Deferred Declined-Financial support

When a student/admissions responses back to the offer, it is captured in a misc table. However, the record does not get created if no responses are captured.

The user wants me to also want me to include students who has not yet responded back to the offer. Thinking this way easy, here's what I did:

Created a stored procedure with three parameters the user asked for. --in this stored procedure, to allow multiple values for the parameter, I used following function:

CREATE FUNCTION CSVToVarChar (  
@List VARCHAR(8000),  
@Delimiter CHAR(1) = ','  
)   
RETURNS TABLE  

AS  
RETURN SELECT CAST(SUBSTRING(@Delimiter + ISNULL(@List,'') + @Delimiter, Number + 1,     CHARINDEX(@Delimiter, @Delimiter + ISNULL(@List,'') + @Delimiter, Number + 1)  - Number - 1) AS VARCHAR(8000)) AS String  
FROM dbo.fff_Number WITH(NOLOCK)  
WHERE SUBSTRING( @Delimiter + ISNULL(@List,'') + @Delimiter, Number, 1 ) = @Delimiter  
    AND Number < LEN( @Delimiter + ISNULL(@List,'') + @Delimiter )    

This function was used this way in where clause of sp:

 AdmissionOffer IN (SELECT string
                       FROM
                           dbo.CSVToVarChar(@AdmissionOffer, ','))

next, I got started to create the report: in report, I created a dataset for admissionoffer parameter using following query to get my parameter values:

SELECT distinct ISNULL(attributevalue, 'No Response') as AdmissionOffer from table....

I also allowed to multiple values in ssrs for this parameter. User would see null in lov as 'No Response'.

What I need help with:

How do I create a report/stored procedure (not sure where i need to make the change) that would work with multiple values and null value is one of them. I am getting nothing when I run the report. If i remove 'No response' value from Admission offer LOV in ssrs, the report works fine.

Well the basic thing you need to know is that NULL and NOT NULL are never going to be mixed when passing a param to a procedure.

Now to get around this - If the actual value of the string split is 'NULL', then I converted it in the split function to a NULL. (Could be anything, but 'NULL' just seemed like it should be the one to use). For me, this was as simple as changing the SQL for my param to union another value - not sure how you are getting your though.

Now because the IN() function does not work with a NULL value in it either, to get around this (and probably a better option in my opinion) is that I inner joined the split table in order to filter.

SELECT *
FROM table a
INNER JOIN dbo.ufn_split(@list,'|') s ON a.pkey = s.value

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM