Quantcast
Channel: SQLServerCentral » SQL Server 2014 » Development - SQL Server 2014 » Latest topics
Viewing all articles
Browse latest Browse all 3145

Recursive family, but how?

$
0
0
Hi,I have a family table and would like to group all related members under the same familyID. This is a replication of existing business data, 14,000 rows. The familyID can be randomly assigned to any group, its sole purpose is to group the names:[code="sql"]declare @tv table (member varchar(255), relatedTo varchar(255))insert into @tvselect 'John', 'Mary'union allselect 'Mary', 'Jessica' union allselect 'Peter', 'Albert' union allselect 'Peter', 'Nancy' union allselect 'Abby', null union allselect 'Jessica', 'Fred' union allselect 'Joe', 'Frank' [/code]I would like my result to look like this:[code="plain"][u]familyID[/u] [u]Name[/u]1 John1 Mary1 Jessica1 Fred2 Peter2 Albert2 Nancy3 Abby4 Joe4 Frank[/code]Thanks a lot!!

Viewing all articles
Browse latest Browse all 3145

Trending Articles