Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
Article Discussions
»
Article Discussions by Author
»
Discuss Content Posted by Frederic Brouard
»
CTEs and Trees
CTEs and Trees
Rate Topic
Display Mode
Topic Options
Author
Message
Frédéric BROUARD
Frédéric BROUARD
Posted Tuesday, December 25, 2007 9:45 PM
Grasshopper
Group: General Forum Members
Last Login: Tuesday, February 12, 2013 3:10 AM
Points: 15,
Visits: 106
Comments posted to this topic are about the item
CTEs and Trees
Post #436287
Jeff Moden
Jeff Moden
Posted Wednesday, December 26, 2007 10:47 AM
SSC-Dedicated
Group: General Forum Members
Last Login: Today @ 8:14 AM
Points: 32,910,
Visits: 26,802
Great code and explanations, but no test data...
--Jeff Moden
"
RBAR
is pronounced "ree-bar" and is a "Modenism" for "
R
ow-
B
y-
A
gonizing-
R
ow".
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."
For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
Post #436419
alen teplitsky
alen teplitsky
Posted Wednesday, December 26, 2007 1:29 PM
Ten Centuries
Group: General Forum Members
Last Login: 2 days ago @ 8:15 PM
Points: 1,409,
Visits: 4,509
i want to play with this in detail when i have time, but we had a problem with an app with similar conditions
we 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
https://plus.google.com/100125998302068852885/posts?hl=en
http://twitter.com/alent1234
x-box live gamertag: i am null
[url=http://live.xbox.com/en-US/MyXbox/Profile[/url]
Post #436487
Frédéric BROUARD
Frédéric BROUARD
Posted Thursday, December 27, 2007 4:11 AM
Grasshopper
Group: General Forum Members
Last Login: Tuesday, February 12, 2013 3:10 AM
Points: 15,
Visits: 106
I make some tests some years ago with different methods :
-> 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 CTE
Interval model was the winner...
Post #436602
alen teplitsky
alen teplitsky
Posted Thursday, June 12, 2008 7:16 PM
Ten Centuries
Group: General Forum Members
Last Login: 2 days ago @ 8:15 PM
Points: 1,409,
Visits: 4,509
what about adding a number column to the master table and using that in your loop?
https://plus.google.com/100125998302068852885/posts?hl=en
http://twitter.com/alent1234
x-box live gamertag: i am null
[url=http://live.xbox.com/en-US/MyXbox/Profile[/url]
Post #516349
Jeff Moden
Jeff Moden
Posted Thursday, June 12, 2008 7:34 PM
SSC-Dedicated
Group: General Forum Members
Last Login: Today @ 8:14 AM
Points: 32,910,
Visits: 26,802
Tech_Newbie (6/12/2008)
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 needed
MasterList(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 list
Lets 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
Ok... third time's the charm... post your request in the correct forum... you'll get better answers quicker.
--Jeff Moden
"
RBAR
is pronounced "ree-bar" and is a "Modenism" for "
R
ow-
B
y-
A
gonizing-
R
ow".
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."
For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
Post #516357
« Prev Topic
|
Next Topic »
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.