Skip to content

Instantly share code, notes, and snippets.

@AlexArchive
Created July 29, 2013 07:40
Show Gist options
  • Save AlexArchive/6102684 to your computer and use it in GitHub Desktop.
Save AlexArchive/6102684 to your computer and use it in GitHub Desktop.
Resolves the category name for a given category ID in the TSQL2012 Database
USE TSQL2012;
SELECT productid, productname, categoryid,
CASE categoryid
WHEN 1 THEN 'Beverages'
WHEN 2 THEN 'Condiments'
WHEN 3 THEN 'Confections'
WHEN 4 THEN 'Dairy Products'
WHEN 5 THEN 'Grains/Cereals'
WHEN 6 THEN 'Meat/Poultry'
WHEN 7 THEN 'Produce'
WHEN 8 THEN 'Seafood'
ELSE 'Unknown Category'
END AS categoryname
FROM Production.Products;
SELECT
Production.Products.productid,
Production.Products.productname,
Production.Products.categoryid,
Production.Categories.categoryname
FROM Production.Products
JOIN Production.Categories
ON Production.Products.categoryid = Production.Categories.categoryid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment