a way to filter using parameters including nul/blanket records?

I am using a paramter to query the table. ProjectTable(id,status,team).

Select * From projectable where team in (@team)

OK this is fine but I also would to include null and blanket value when I select all teams from the parameters.

How can I do that?
dkim18Asked:
Who is Participating?
 
aelliso3Connect With a Mentor Commented:

If you only want to include null and blank values when you select all, then there's a couple of steps to it. The suggestion above will include NULL values when any query is returned.

In your query that provides the paramater values, do a union to add in the first row like below:

SELECT id=999, Status='', team = 'SELECT ALL'
UNION
SELECT id, status, team FROM projectable

This will add one more value to your list that will bring back everything if selected. Otherwise, you'll only get what you selected without the Nulls and blanks.

Select id, active, team
From projectable
where id in (@team)
     or @team = 'SELECT ALL'
0
 
nognewConnect With a Mentor Commented:
Hi there!
 how about that:
Cheers,
t.
Select * From projectable where team in (@team) or team is null

Open in new window

0
 
AmmarRConnect With a Mentor Commented:
Dear dkim18

check the code below,
SELECT * FROM projectable  where team in (@pteam) or (@pteam is null and team is null)

Open in new window

0
 
dkim18Author Commented:
o
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.