Created
July 29, 2013 07:40
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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