April 9, 2010 at 8:03 am
Hi guys,
I have a query in one of my reporting services reports which is based on a case statement that uses a wildcard. (e.g. HAVING DIRECTORATE_CODE LIKE CASE WHEN @Directorate = 'ALL' THEN '%%' ELSE @Directorate END).
This code is supposed to show all records for directorate when the 'ALL' option is selected from the report filter combo box. This works fine BUT it is currently excluding null values. I'm assuming that the % wildcard ignores nulls.
Is there anyway i can get the case statement (or more specifically the 'THEN' statement) to show all records including the null values when 'ALL' is seleceted?
Regards,
Shuja
April 9, 2010 at 8:05 am
Try
HAVING DIRECTORATE_CODE LIKE CASE WHEN @Directorate = 'ALL' THEN DIRECTORATE_CODE ELSE @Directorate END)
______________________________________________________________________
Personal Motto: Why push the envelope when you can just open it?
If you follow the direction given HERE[/url] you'll likely increase the number and quality of responses you get to your question.
Jason L. SelburgApril 9, 2010 at 8:24 am
Hi Jason,
I tried your solution but i get the same record count and the null value records aren't showing.
I also tried to enclose the DIRECTORATE_CODE in wildcards ('%' + DIRCETORATE_CODE + '%') but this did the same thing as your solution. I'm getting the same results from all of these methods - no null value records showing.
Any other ideas?
Shuja
April 9, 2010 at 8:36 am
I think i might have found the solution after fiddling with Jason's original solution.
I've added a COALESCE to the DIRECTORATE_CODE at both end s of the case statement so that null values are compared as text values.
(e.g. HAVING (COALESCE(DIRECTORATE_CODE,'NULL') LIKE CASE WHEN @Directorate= 'ALL' THEN COALESCE(DIRECTORATE_CODE,'NULL') ELSE 'ALL' END)
April 9, 2010 at 8:37 am
Thanks for your help Jason.
Regards, Shuja
April 9, 2010 at 10:58 am
shujaahmad2004 (4/9/2010)
Hi guys,I have a query in one of my reporting services reports which is based on a case statement that uses a wildcard. (e.g. HAVING DIRECTORATE_CODE LIKE CASE WHEN @Directorate = 'ALL' THEN '%%' ELSE @Directorate END).
This code is supposed to show all records for directorate when the 'ALL' option is selected from the report filter combo box. This works fine BUT it is currently excluding null values. I'm assuming that the % wildcard ignores nulls.
Is there anyway i can get the case statement (or more specifically the 'THEN' statement) to show all records including the null values when 'ALL' is seleceted?
Regards,
Shuja
this is simpler:
(@directorate = 'ALL' or directorate_code like @directorate)
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply