Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Query help: with root, find all child nodes
Message
De
05/12/2004 09:44:26
Alvin Lourdes
Children and Youth Services Cluster
Toronto, Ontario, Canada
 
 
À
05/12/2004 01:41:09
Alvin Lourdes
Children and Youth Services Cluster
Toronto, Ontario, Canada
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
00966953
Message ID:
00966968
Vues:
8
I think that this might work..
INSERT INTO parentchildtemp
(child)
VALUES('E986A368-D298-4365-8322-8B57DED43707')

DECLARE @topcust as varchar(100)
WHILE EXISTS(SELECT * FROM parentchildtemp)
BEGIN
	SET @topcust = (SELECT TOP 1 child FROM parentchildtemp)
	INSERT INTO parentchildtemp
	(child)
	SELECT customerid  FROM customer
	WHERE referralid = @topcust

	INSERT INTO parentchild
	(parent,child,currentpos)
	SELECT @topcust,c.customerid,cdt.currentstatus FROM customer c
	INNER JOIN customertotable cdt 
	ON c.customerid = cdt.customerid
	WHERE referralid = @topcust

	DELETE FROM parentchildtemp
	WHERE child = @topcust
END
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform