View Single Post

   
  #2 (permalink)  
Old 02-28-2008, 06:14 PM
John Gilson
 
Posts: n/a
Default Re: CASE Statement in Where Clause?

"Largo SQL Tools" <support@_REMOVE_largosqltools.com> wrote in message
news:v5adnTcJ84Mdbh-iXTWJiw@buckeye-express.com...
> Can anyone tell me if it's possible to use a Case statement in a Where
> clause, and if so, the proper syntax?
>
> J.R.
> Largo SQL Tools
> The Finest Collection of SQL Tools Available
> http://www.largosqltools.com


CASE is an expression, not a statement, and, as such, returns a value.
It can indeed be used in a WHERE clause. For example,

SELECT *
FROM T
WHERE col1 = CASE WHEN col2 < col3
THEN col2
ELSE col3
END

Regards,
jag


Reply With Quote