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 2000 Forums
 SQL Server Development (2000)
 Where Condition Pbm

Author  Topic 

Nitz
Starting Member

3 Posts

Posted - 2010-10-08 : 16:28:23
select * from contact
where status in (4,5)

This is my Query..
here the table 'contact' has a field userid

now i need to fetch the row with status = 2 and userid is not null
(ie) select * from contact
where userid is not null
and status = 2

i want to merge the above 2 condns

that is, status in (2,4,5) but status 2 should be considered only when userid is not null

Please help me out..

Thanks in advance :)

~hard work never fails~

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-10-08 : 16:34:48
select *
from contact
where status in (4, 5) or (status = 2 and userid is not null)

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

Nitz
Starting Member

3 Posts

Posted - 2010-10-08 : 16:36:20
is that userid in (4,5) or status in (4,5) ?

~hard work never fails~
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-10-08 : 16:39:37
Oops. Yes switch it.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

Nitz
Starting Member

3 Posts

Posted - 2010-10-08 : 18:23:36
Hey this works pakka..!!! Thanks a lot !! :)

~hard work never fails~
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-10-08 : 18:26:27
You're welcome, glad to help.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -