OR with WHEN

  • Can the WHEN part of a CASE statement contain an OR clause? If so, what is the proper syntax?

  • Yes.

    Here is an example:

    use pubs

    go

    select case when city = 'Oakland' or city = 'Menlo Park'

    then 'Change City'

    else city

    end

    from authors

    Gregory Larsen, DBA

    If you looking for SQL Server Examples check out my website at http://www.geocities.com/sqlserverexamples

    Gregory A. Larsen, MVP

  • Perfectly legitimate.

    Here is another example

    SELECT CASE WHEN CONVERT(CHAR,GETDATE(),101) = '11/06/2002' OR DATEPART(dw,GETDATE()) = 3 THEN 'YES' ELSE 'NOPE' END

  • yes! that's it. thank you

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply