Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need help on CASE usage in Where clause

Status
Not open for further replies.

hnkadmn

MIS
Sep 22, 2003
13
0
0
US
here I am giving only where clause. existing where clause is having so many or conditions, can I replace with Case.
Please suggest.

Where
( a = 1 and b=2) or
(a=3 and b=4) or
(a=4 and b=8)

Can replace with

Where
Case
When ( a = 1 and b=2) then " here what should we do"
When (a=3 and b=4) then "here what should we do"
When (a=4 and b=8) then "here what should we do"
Else null ("is it ok")
End is not null


Hari
 
Hari,

The CASE expression is not used in the where clause but in the select part:

Select
Case
When ( a = 1 and b=2) then " here what should we do"
When (a=3 and b=4) then "here what should we do"
When (a=4 and b=8) then "here what should we do"
Else "is it ok"
End
from..................

T. Blom
Information analyst
tbl@shimano-eu.com
 
Hi Blom

Thanks for your suggestion. I tried executing the SQL, it gave same result as having multiple OR's. But it took more CPU time.

Hari
 
Where did you put the Case Statements - in the Select or the Where clause?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top