Solved

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

Posted on 2010-09-20
4
252 Views
Last Modified: 2012-05-10
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?
0
Comment
Question by:dkim18
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 8

Assisted Solution

by:nognew
nognew earned 100 total points
ID: 33718297
Hi there!
 how about that:
Cheers,
t.
Select * From projectable where team in (@team) or team is null

Open in new window

0
 
LVL 11

Accepted Solution

by:
aelliso3 earned 300 total points
ID: 33718657

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
 
LVL 15

Assisted Solution

by:AmmarR
AmmarR earned 100 total points
ID: 33718718
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
 

Author Closing Comment

by:dkim18
ID: 33833865
o
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

A recent questions about how to add SSRS named instances, couldn't find any that talks about SQL server 2008, anyway I decided to help by creating some screen shots. The installation is straightforward, you just pop the SQL server 2008 installati…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

710 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