Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2010-09-20
4
Medium Priority
?
254 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 400 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 1200 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 400 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

TCP/IP Network Protocol Cheat Sheet

TCP/IP is a set of network protocols which is best known for connecting the machines that make up the Internet. The truth is that TCP/IP is one of the oldest network protocols and its survival is mainly based on its simplicity and universality.

Question has a verified solution.

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

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…
If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

670 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