Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Help with an SQL Select Statement

Author  Topic 

jcnewman83
Starting Member

6 Posts

Posted - 2011-02-02 : 16:01:37
HI,

I need some help with a Select statement.

I have a table that looks similar to the below

Name Code Data1 Data1 Data3
Fred A123 ghghg ftftft gygygy
Bill A456 hghhh hyupu
Ann A789 hghghg
Sarah A012 ghtsa

What I want is a select statement that will return all rows in this table where there is no data in the Data 1,2 and 3 columns, so basically what I would want to see returned is:

Name Code Data1 Data1 Data3
Bill A456 hghhh hyupu
Ann A789 hghghg
Sarah A012 ghtsa

can someone help get me on the correct path on this one??
Thanks in advance for anyone's help.

srujanavinnakota
Starting Member

34 Posts

Posted - 2011-02-02 : 17:14:10
Try this..

Select * FROM yourTable WHERE (Data1='' OR Data1 is null)
UNION
Select * FROM yourTable WHERE (Data2='' OR Data2 is null)
UNION
Select * FROM yourTable WHERE (Data3='' OR Data3 is null)
Go to Top of Page

Ranjit.ileni
Posting Yak Master

183 Posts

Posted - 2011-02-02 : 23:28:54
Try this ..

select *
from [yourtable]
where Data1 is null or Data2 is null or Data3 is null

IRK
Go to Top of Page

jcnewman83
Starting Member

6 Posts

Posted - 2011-02-03 : 06:28:06
This worked like a charm, thank you.

quote:
Originally posted by srujanavinnakota

Try this..

Select * FROM yourTable WHERE (Data1='' OR Data1 is null)
UNION
Select * FROM yourTable WHERE (Data2='' OR Data2 is null)
UNION
Select * FROM yourTable WHERE (Data3='' OR Data3 is null)

Go to Top of Page
   

- Advertisement -