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)
 CASE IN WHERE CLAUSE

Author  Topic 

vladimir_grigoro
Yak Posting Veteran

62 Posts

Posted - 2003-02-20 : 08:09:09
Hi All,

Is there any chance to use CASE statement after WHERE?

Thanks in advcance.

The Rebel

Bambola
Posting Yak Master

103 Posts

Posted - 2003-02-20 : 09:30:28
Sure. What is it that you are looking for exactly?

Bambola.

Go to Top of Page

ValterBorges
Master Smack Fu Yak Hacker

1429 Posts

Posted - 2003-02-20 : 09:41:08
http://www.databasejournal.com/features/mssql/article.php/1438901
http://www.databasejournal.com/features/mssql/article.php/1460001

Go to Top of Page

vladimir_grigoro
Yak Posting Veteran

62 Posts

Posted - 2003-02-20 : 09:59:38
WHERE CASE
X IS NULL THEN X>Y
Y IS NOT NULL THEN Y<X
END

I am looking for something like that but I am not sure that is it possible.

quote:

Sure. What is it that you are looking for exactly?

Bambola.





The Rebel
Go to Top of Page

Page47
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2003-02-20 : 10:34:12
You do realize that if X is null, then X>Y will evaluate to NULL, thus the predicate will always be false.

Jay White
{0}
Go to Top of Page

vladimir_grigoro
Yak Posting Veteran

62 Posts

Posted - 2003-02-20 : 10:37:48
No I just gave an example it could be any value:)

quote:

You do realize that if X is null, then X>Y will evaluate to NULL, thus the predicate will always be false.

Jay White
{0}



The Rebel
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2003-02-20 : 11:07:49
I could be wrong (again) but I don't think that is syntactically correct. I think you can do something like:

WHERE CASE WHEN X IS NULL THEN Y ELSE X END > CASE WHEN Y IS NULL THEN X ELSE Y END

Again the example doesn't make much sense with out a business reason....

Am I missing something though? Any comments appreciated.

Brett

8-)

Go to Top of Page

Onamuji
Aged Yak Warrior

504 Posts

Posted - 2003-02-20 : 11:16:27
why do you need the case at all

WHERE (X IS NULL AND X>Y) OR (Y IS NOT NULL AND Y<X)

Go to Top of Page
   

- Advertisement -