-------------------------------------------------------------------------------- A. Using a SELECT statement with a simple CASE function USE AdventureWorks; GO SELECT ProductNumber, Category = CASE ProductLine WHEN 'R' THEN 'Road' WHEN 'M' THEN 'Mountain' WHEN 'T' THEN 'Touring' WHEN 'S' THEN 'Other sale items' ELSE 'Not for sale' END, Name FROM Production.Product ORDER BY ProductNumber; GO -------------------------------------------------------------------------------- B. Using a SELECT statement with simple and searched CASE function USE AdventureWorks; GO SELECT ProductNumber, Name, 'Price Range' = CASE WHEN ListPrice = 0 THEN 'Mfg item - not for resale' WHEN ListPrice < 50 THEN 'Under $50' WHEN ListPrice >= 50 and ListPrice < 250 THEN 'Under $250' WHEN ListPrice >= 250 and ListPrice < 1000 THEN 'Under $1000' ELSE 'Over $1000' END FROM Production.Product ORDER BY ProductNumber ; GO -------------------------------------------------------------------------------- C. Using CASE to replace the IIf function that is used in Microsoft Access SELECT FirstName, Lastname, TelephoneNumber, IIf(IsNull(TelephoneInstructions),"Any time", TelephoneInstructions) AS [When to Contact] FROM db1.ContactInfo USE AdventureWorks GO SELECT FirstName, Lastname, TelephoneNumber, 'When to Contact' = CASE WHEN TelephoneSpecialInstructions IS NULL THEN 'Any time' ELSE TelephoneSpecialInstructions END FROM Person.vAdditionalContactInfo