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 2012 Forums
 Transact-SQL (2012)
 Concatenation of hierarchal data

Author  Topic 

boggyboy
Yak Posting Veteran

57 Posts

Posted - 2013-01-28 : 08:23:35
I have hierarchal data that looks like below with parent/child relationships defined.

Item,ID, ParentID
CEO, 1, null
CIO, 2, 1
COO, 3, 1
VP of Dev, 4, 2
VP of Infrastructure, 5, 2
VP of Marketing, 6, 3
VP of Support, 7, 2
VP of Sales, 8, 3
Sales Executive 1, 9, 8
Sales Executive 2, 10, 8
Marketing Executive 1, 11, 6
Marketing Executive 2, 12, 6
Dev Executive 1, 13, 4
Dev Executive 2, 14, 4


I want to return the following:
Item,ID, ParentID
CEO, 1, null,CEO
CIO, 2, 1,CEO.CIO
COO, 3, 1,CEO.COO
VP of Dev, 4, 2,CEO.COO.VP of Dev
VP of Infrastructure, 5, 2, CEO.COO.VP of Infrastructure
VP of Marketing, 6, 3, CEO.COO.VP of Marketing
VP of Support, 7, 2, CEO.COO.VP of Support
VP of Sales, 8, 3,CEO.COO.VP of Sales
Sales Executive 1, 9, 8, CEO.COO.VP of Sales.Sales Executive 1

and so on... where the new column is the full "Dot" notation

I need some kind of recursive query. Thanks in advance!

Meghan

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-01-28 : 08:38:28
see same scenario discussed here
http://msdn.microsoft.com/en-us/library/ms186243(v=sql.105).aspx

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -