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 2000 Forums
 Transact-SQL (2000)
 SQL help needed!

Author  Topic 

padsp
Starting Member

21 Posts

Posted - 2005-05-25 : 17:13:18
Hi everyone,

I have a table called Contact
Columns in Contact are (estabID,contactID,typeID,Name)
Samples rows in Contact table are:

estabID contactID typeID Name
21 882 4 Coverly Marva
21 882 5 Coverly Marva
21 882 6 Coverly Marva
21 883 2 Shareef Mal
21 886 3 Victor
21 886 4 Victor
21 886 11 Victor

typeID means: 2=CEO,3=GM,4=List,5=Manager,6=Owner,11=Misc

I would like to have the final output as follows:-

estabID contactID Name CEO GM List Mgr Owner Misc
21 882 CMarva F F T T T F
21 883 SMal T F F F F F
21 886 Victor F T T F F T

here F means:False; T means: True
I am trying to accomplish something like this:-
SELECT estabID,contactID,Name
Case typeID when 4 then ‘True’ else ‘False’ …
FROM contact

I couldn’t get the result set, what I am looking for.
I need your help.

Thanks
Bob

nosepicker
Constraint Violating Yak Guru

366 Posts

Posted - 2005-05-25 : 17:45:29
See if this works for you:

SELECT A.estabID, A.contactID, A.name,
MAX(A.CEO) AS CEO, MAX(A.GM) AS GM, MAX(A.List) AS List, MAX(A.Mgr) AS Mgr, MAX(A.Owner) AS Owner, MAX(A.Misc) AS Misc
FROM
(SELECT estabID, contactID, name,
CASE WHEN typeID = 2 THEN 'T' ELSE 'F' END AS CEO,
CASE WHEN typeID = 3 THEN 'T' ELSE 'F' END AS GM,
CASE WHEN typeID = 4 THEN 'T' ELSE 'F' END AS List,
CASE WHEN typeID = 5 THEN 'T' ELSE 'F' END AS Mgr,
CASE WHEN typeID = 6 THEN 'T' ELSE 'F' END AS Owner,
CASE WHEN typeID = 11 THEN 'T' ELSE 'F' END AS Misc
FROM contact) AS A
GROUP BY A.estabID, A.contactID, A.name
Go to Top of Page

padsp
Starting Member

21 Posts

Posted - 2005-05-26 : 11:50:50
Hi nosepicker,

Thank you for your time to read my post and reply for it.
It's working perfectly. Again Thanks.

Bob
Go to Top of Page
   

- Advertisement -