Re: WHERE statement conditions
- From: --CELKO-- <jcelko212@xxxxxxxxxxxxx>
- Date: Mon, 14 Sep 2009 12:23:30 -0700 (PDT)
Here is a quick trick for converting IF-THEN-ELSE procedural code in
declarative CASE expressions:
SELECT *
FROM MyTable
WHERE CASE WHEN company_name = 'LL'
THEN 'T'
WHEN company_name NOT IN ('XX', 'YY', 'ZZ')
AND col2 = 'P'
THEN 'T' ELSE 'F' END = 'T';
The CASE expression evaluates the WHEN clauses in order and returns
the value in the matching THEN clause as the result. The data type of
the CASE expression is the highest one in all the THEN clauses.
.
- Follow-Ups:
- Re: WHERE statement conditions
- From: Rick
- Re: WHERE statement conditions
- References:
- WHERE statement conditions
- From: Rick
- WHERE statement conditions
- Prev by Date: WHERE statement conditions
- Next by Date: Pivoting A Table
- Previous by thread: WHERE statement conditions
- Next by thread: Re: WHERE statement conditions
- Index(es):
Relevant Pages
|