Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 case......when ..then

Author  Topic 

marek
Starting Member

34 Posts

Posted - 2011-05-12 : 03:52:15
I have following problem....I find in this forum, but "case" not working.

TabBranch

branch employe
100 Bill
100 George
200 Mark
300 Bruce
300 Willis

result
Washington Bill
Washington George
Dallas Mark
Chicago Bruce
Chicago Willis

Where I have eror?

Select branch
case branch when '100' then 'Washington'
case branch when '200' then 'Dallas'
case branch when '300' then 'Chicago'

thanks boys...



lionofdezert
Aged Yak Warrior

885 Posts

Posted - 2011-05-12 : 03:58:32
CREATE TABLE #TabBranch (branch INT, employe VARCHAR(50))
INSERT INTO #TabBranch
SELECT 100, 'Bill' UNION ALL
SELECT 100, 'George' UNION ALL
SELECT 200, 'Mark' UNION ALL
SELECT 300, 'Bruce' UNION ALL
SELECT 300, 'Willis'

SELECT CASE branch WHEN 100 THEN 'Washington'
WHEN 200 THEN 'Dallas'
WHEN 300 THEN 'Chicago' ELSE '' END AS branch,
employe
FROM #TabBranch

DROP TABLE #TabBranch


--------------------------
http://connectsql.blogspot.com/
Go to Top of Page

marek
Starting Member

34 Posts

Posted - 2011-05-12 : 05:52:38
thanks lionofdezert
Go to Top of Page
   

- Advertisement -