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
 Transact-SQL (2000)
 Conditional where

Author  Topic 

t1g312
Posting Yak Master

148 Posts

Posted - 2005-02-20 : 02:50:13
Hi all,

I need to use a where condition based on the value of a particular field.
E.g.:

select a,b,c from table where case a = 'something' then
b = 'efg'
else
c = 'xyz'
end

I know the above query is wrong, but I hope you get what I'm trying to acheive. How do I go about it?

Thanks in advance,

Adi

-------------------------
/me sux @sql server

Kristen
Test

22859 Posts

Posted - 2005-02-20 : 07:43:56
[code]
select aaaaa,bbbbb,ccccc
from table
WHERE (aaaaa = 'something' AND bbbbb = 'efg')
OR (
(aaaaa <> 'something' OR aaaaa IS NULL)
AND ccccc = 'xyz'
)
[/code]
Go to Top of Page

t1g312
Posting Yak Master

148 Posts

Posted - 2005-02-20 : 08:13:02
quote:
Originally posted by Kristen


select aaaaa,bbbbb,ccccc
from table
WHERE (aaaaa = 'something' AND bbbbb = 'efg')
OR (
(aaaaa <> 'something' OR aaaaa IS NULL)
AND ccccc = 'xyz'
)




Super!!! Thanks Kristen!

Adi

-------------------------
/me sux @sql server
Go to Top of Page
   

- Advertisement -