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)
 Convert Rows to Columns

Author  Topic 

oitsubob
Yak Posting Veteran

70 Posts

Posted - 2005-10-11 : 22:58:06
Hi All!
I'm working on a hierarchy table using a SQL Tree based on a model described by Joe Celko.

http://www.intelligententerprise.com/001020/celko.jhtml?_requestid=49180

In his example #1), he shows a query to find the employee and all of his/her supervisors.

What I need to do is convert that from:

supervisor4 (VP)
supervisor3 (General Manger)
supervisor2 (District Manger)
supervisor1 (First Level Manager)
employee

To:

employee supervisor1 supervisor2 supervisor3 supervisor4

Does anyone have any tips on how to go about doing something like that?

Keep in mind, this isn't going to be done for one employee at a time, but for several thousand. Also, there might be times where the employee reports directly to the district manager rather than to a First Level Manager so I'd need for that column's value to be null while the others would be populated.

Any help would be appreciated.

Thanks,

Bob

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2005-10-12 : 05:29:34
http://weblogs.sqlteam.com/jeffs/archive/2005/05/02/4842.aspx
http://weblogs.sqlteam.com/jeffs/archive/2005/05/15/5175.aspx
http://weblogs.sqlteam.com/jeffs/archive/2005/05/11/5101.aspx

Go with the flow & have fun! Else fight the flow
Go to Top of Page

oitsubob
Yak Posting Veteran

70 Posts

Posted - 2005-10-13 : 11:22:56
That worked incredibly well! Thanks for the tip :)

Bob
Go to Top of Page

pvinesh
Starting Member

3 Posts

Posted - 2008-03-14 : 06:30:22
I have a table with only one column as

Emp_Name
A
B
C
D
E

I want to display this data as

Emp_Name
A, B, C, D, E

Is this possible? I am using SQL server 2005.
Any help is appreciated.

Regards,
Vinesh
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-03-14 : 06:59:40
Don't hijack topics!
But for your question, see http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=81254



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

Xerxes
Aged Yak Warrior

666 Posts

Posted - 2008-03-25 : 11:38:32
Some of this one is jumbled: http://weblogs.sqlteam.com/jeffs/archive/2005/05/02/4842.aspx

Semper fi,
XERXES, USMC(Ret.)
------------------------------------------------------
The Marine Corps taught me everything but SQL!
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2008-03-25 : 11:43:35
amazing... you're still alive??

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
SSMS Add-in that does a few things: www.ssmstoolspack.com
Go to Top of Page
   

- Advertisement -