Re: CASE WHEN Equivalent in WHERE Clause?
am 30.03.2008 23:50:43 von Hugo KornelisOn Fri, 28 Mar 2008 11:40:05 -0700 (PDT), --CELKO-- wrote:
>>> Is there an equivalent construction to the CASE WHEN statement that can be used in the WHERE clause? <<
>
>1) There is no CASE statement in SQL; but we do have a CASE
>expression. You still have a procedural mindset and have not started
>thinking in sets.
>
>2) I am guessing that you want to write a **predicate** something like
>this:
>
>DECLARE @FirstName NVARCHAR(35);
>
> SELECT first_name, last_name
> FROM Contacts
> WHERE
> CASE WHEN @first_name = 'Bob' AND bluehair = 1
> THEN 'T'
> WHEN @first_name = 'Frank' AND pastaeater = 1
> THEN 'T'
> WHEN hat_size > 5.0
> THEN 'T' ELSE 'F' END = 'T';
Hi Joe,
This is not equivalent to what Lauren Quantrell wanted. The version
posted by Plamen Ratchev is better.
--
Hugo Kornelis, SQL Server MVP
My SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis