Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Recursive Queries Expand / Collapse
Author
Message
Posted Tuesday, October 27, 2009 10:17 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Monday, April 11, 2011 12:49 AM
Points: 69, Visits: 179
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
Posted Tuesday, October 27, 2009 10:45 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Wednesday, August 31, 2011 7:47 AM
Points: 30, Visits: 154
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
Posted Tuesday, October 27, 2009 11:14 AM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Yesterday @ 9:04 PM
Points: 23,302, Visits: 32,057
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
Posted Wednesday, October 28, 2009 3:28 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Tuesday, August 26, 2014 5:08 AM
Points: 363, Visits: 1,319
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
Posted Wednesday, October 28, 2009 9:00 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: 2 days ago @ 9:58 AM
Points: 36,995, Visits: 31,517
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 "Row-By-Agonizing-Row".

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."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #810466
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse