SQL Case Example

A little example for using CASE in an MS-SQL database. From a ColdFusion page.

SELECT dbo_MerchGroup_code, dbo_MerchGroup_description, inStore_Rank,
isNew =
CASE
WHEN (new_until > GETDATE()) THEN 1
ELSE 0
END
FROM merchgroup
WHERE (inStore_Rank IS NOT NULL) AND (dbo_MerchGroup_code IN (#MerchGroupList#))
ORDER BY inStore_Rank

 

 

And... using a list... 

 

SELECT style, 

CASE WHEN [Class] IN ('32','34', '29', '28', '81', '33', '36', '31', '25', '38', '60', '67', '40', '26', '42')

THEN 'Clothes' ELSE 'Nope' END AS IsThisClothes

FROM STYLE

 

 

tags: sqlserver, case, syntax

Related Scribbles:
  • SQL Syntax, Query Examples and Notes
  • SQL Server


  • ID: 570
    Author:
    leonard
    Date Updated:
    2018-07-05 14:58:15
    Date Created:
    2004-11-09 11:49:50

    Edit

    Comments?
     >> Leonard Chan's Homepage  >> Scribble Web  >> SQL Case Example
    leonard.lotus-land.ca is hosted by Perceptus Solutions Inc.