TransactSQL - Two case statements in One Select Statement Outputting to one Column
Go to solution
Solved by Franck,
42 minutes ago, adman29 said:Hi all,
I basically need to have two case statements outputting to two columns in Transact SQL. I have the first half here:
USE AdventureWorks2017 Select CASE WHEN PersonType = 'SC' then 'Store Contact' WHEN PersonType = 'IN' then 'Individual (retail) Customer' WHEN PersonType = 'SP' then 'Sales Person' WHEN PersonType = 'EM' then 'Employee (non-sales)' WHEN PersonType = 'VC' then 'Vendor Contact' WHEN PersonType = 'GC' then 'General Contact' ELSE '' END AS PersonTypeEvaluated From Person.PersonI need to have it basically concatenate FirstName MiddleName and LastName in the second Case statement.
Do 2 queries with union.
Example :
SELECT PersonType, '' AS 'Name' FROM Person WHERE PersontType <> 'IN' UNION SELECT PersonType, FirstName + ' ' + MiddleName + ' ' + LastName as 'Name' FROM Person WHERE PersontType == 'IN'
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now