June 10, 2015 at 6:50 am
I would like to pull data from two seperate columns based on the vaule for MakeFlag. So if MakeFlag = 0 I would
like the description to show but anything else I would like catalog description to show up.
DECLARE @MyVari varchar(20)
SELECT [ProductID]
,[prod].[Name]
,[ProductNumber]
,[MakeFlag]
,[FinishedGoodsFlag]
,[MyRow] = @MyVari
FROM [AdventureWorks2014].[Production].[Product] prod
INNER JOIN [Production].[ProductModel] Prodmod
ON prod.Name = Prodmod.name
WHERE Case When
[Production].[Product].[MakeFlag] = 0 Then @MyVari = [prod].[ProductModelID]
Else @MyVari = [Prodmod].[CatalogDescription]
END
June 10, 2015 at 11:34 am
DECLARE @MyVari varchar(20)
SELECT [ProductID]
,[prod].[Name]
,[ProductNumber]
,[MakeFlag]
,[FinishedGoodsFlag]
,[MyRow] = @MyVari
FROM [AdventureWorks2014].[Production].[Product] prod
INNER JOIN [Production].[ProductModel] Prodmod
ON prod.Name = Prodmod.name
WHERE @MyVari = Case When [Production].[Product].[MakeFlag] = 0
Then [prod].[ProductModelID]
Else [Prodmod].[CatalogDescription]
END
SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply