Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Advertise
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 2005
»
Development
»
Recursive Queries
Recursive Queries
Rate Topic
Display Mode
Topic Options
Author
Message
martin.edward
martin.edward
Posted Tuesday, October 27, 2009 10:17 AM
SSC Rookie
Group: General Forum Members
Last Login: Thursday, March 11, 2010 3:50 AM
Points: 40,
Visits: 113
Hello,
I am in the process of creating a recursive query, but have no idea on the basics i.e. recursion,looping through sql statements etc.
Could some give me a drill down ?
Post #809445
Lewis Dowson
Lewis Dowson
Posted Tuesday, October 27, 2009 10:45 AM
SSC Rookie
Group: General Forum Members
Last Login: Tuesday, March 09, 2010 10:39 AM
Points: 25,
Visits: 125
Hi,
Can you give a llittle more info on exactly what it is you need a loop for?
For the time being have a look at the following article (SQL Server 2005, wont work on 2000)
http://msdn.microsoft.com/en-us/library/ms186243.aspx
Post #809462
Lynn Pettis
Lynn Pettis
Posted Tuesday, October 27, 2009 11:14 AM
SSChampion
Group: General Forum Members
Last Login: Today @ 7:33 PM
Points: 11,937,
Visits: 12,051
Your question is pretty open-ended. It would help us in helping you if you could provide more specifics regarding your problem. Please take the time to also read the first article I reference below in my signature block regarding asking for assistance. if you follow the instructions in that article you we get much better answers to your questions.
Lynn Pettis
For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here
or
when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here
and
here
Managing Transaction Logs
SQL Musings from the Desert
Fountain Valley SQL
(My Mirror Blog)
Post #809480
dmoldovan
dmoldovan
Posted Wednesday, October 28, 2009 3:28 AM
SSC Veteran
Group: General Forum Members
Last Login: Yesterday @ 3:29 AM
Points: 258,
Visits: 820
If you're interested in how the recursive queries work, see
http://sqlblog.com/blogs/linchi_shea/archive/2009/04/16/recursive-sql-queries-how-do-they-work.aspx
Post #809767
Jeff Moden
Jeff Moden
Posted Wednesday, October 28, 2009 9:00 PM
SSChampion
Group: General Forum Members
Last Login: Yesterday @ 9:01 PM
Points: 20,164,
Visits: 13,702
martin.edward (10/27/2009)
Hello,
I am in the process of creating a recursive query, but have no idea on the basics i.e. recursion,looping through sql statements etc.
Could some give me a drill down ?
The only time you should use recursion is for hierarchies. The only time you should use a loop is for flow control across tables or databases... that leaves out 99.9% of all queries.
Rather than learn the wrong way to do things by learning recursion and loops first, take a look at the following article for an alternative to needing most loops...
http://www.sqlservercentral.com/articles/T-SQL/62867/
--Jeff Moden
"
RBAR
is pronounced "ree-bar" and is a "Modenism" for "
R
ow-
B
y-
A
gonizing-
R
ow".
"Data isn't the only thing that's supposed to have Integrity."
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 #810466
« 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-2010 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use