﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Discuss Content Posted by Frederic Brouard / Article Discussions / Article Discussions by Author  / CTEs and Trees / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Sun, 19 May 2013 01:14:56 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: CTEs and Trees</title><link>http://www.sqlservercentral.com/Forums/Topic436287-226-1.aspx</link><description>[quote][b]Tech_Newbie (6/12/2008)[/b][hr]help please.I have the following situation:I want to populate two related tables Person (PersonID, PersonName, PersonLName)PersonAddress(PersonAddressID, PersonID, PersonAddr, PersonCity, PersonState, PersonZip, County)from a table which contains all the data neededMasterList(PersonName, PersonLName, PersonAddr, PersonCity, PersonState, Personzip, County)The thing is I am not doing this sequentially, I want to select every 7th person starting from the person in the MasterList table at position 3.For example:I have 100 people in the master listLets say that I want 30 people to be put into the Persons table and into thier associated address tables. I want to be able to increment through the MasterList table starting at the person from position 3, and insert every 7th person thereafter into the tables.If I get to the end of the table and I have not reached my 30 people, I need to loop back around starting at a new position - 2 and then repeat selecting every 7th person from then on out.Important things: 1. PersonID is an identity, and an auto - incremented value, but within this loop, when I create my entry for Person, I want to turn around and create an entry for PersonAddress, using the newly created PersonID identity value as a foreign key inside of PersonAddress. How should I write a cte to be able to acomplish this ? Thanks for any assistance provided[/quote]Ok... third time's the charm... post your request in the correct forum... you'll get better answers quicker.</description><pubDate>Thu, 12 Jun 2008 19:34:22 GMT</pubDate><dc:creator>Jeff Moden</dc:creator></item><item><title>RE: CTEs and Trees</title><link>http://www.sqlservercentral.com/Forums/Topic436287-226-1.aspx</link><description>what about adding a number column to the master table and using that in your loop?</description><pubDate>Thu, 12 Jun 2008 19:16:47 GMT</pubDate><dc:creator>alen teplitsky</dc:creator></item><item><title>RE: CTEs and Trees</title><link>http://www.sqlservercentral.com/Forums/Topic436287-226-1.aspx</link><description>I make some tests some years ago with different methods :-&amp;gt; tree with classic father/son auto reference (in fac my computer file system including the 4 disks I have)  a) using temp table and a store proc to find some files having '%toto%' in the file name  b) using a path stored with the data in a column NAVARCHAR(4000)  c) using interval model  d) using CTEInterval model was the winner...</description><pubDate>Thu, 27 Dec 2007 04:11:28 GMT</pubDate><dc:creator>Frédéric BROUARD</dc:creator></item><item><title>RE: CTEs and Trees</title><link>http://www.sqlservercentral.com/Forums/Topic436287-226-1.aspx</link><description>i want to play with this in detail when i have time, but we had a problem with an app with similar conditionswe have a table with data and need to return it in hierchial fashion. someone wrote and sp years ago that used a while loop and temp tables. i just rewrote it with a CTE and it seems to run a lot faster</description><pubDate>Wed, 26 Dec 2007 13:29:43 GMT</pubDate><dc:creator>alen teplitsky</dc:creator></item><item><title>RE: CTEs and Trees</title><link>http://www.sqlservercentral.com/Forums/Topic436287-226-1.aspx</link><description>Great code and explanations, but no test data...</description><pubDate>Wed, 26 Dec 2007 10:47:38 GMT</pubDate><dc:creator>Jeff Moden</dc:creator></item><item><title>CTEs and Trees</title><link>http://www.sqlservercentral.com/Forums/Topic436287-226-1.aspx</link><description>Comments posted to this topic are about the item [B]&lt;A HREF="/articles/CTE/61510/"&gt;CTEs and Trees&lt;/A&gt;[/B]</description><pubDate>Tue, 25 Dec 2007 21:45:06 GMT</pubDate><dc:creator>Frédéric BROUARD</dc:creator></item></channel></rss>