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



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

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC 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
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: 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
Posted Tuesday, October 27, 2009 11:14 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

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
Posted Wednesday, October 28, 2009 3:28 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC 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
Posted Wednesday, October 28, 2009 9:00 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

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 "Row-By-Agonizing-Row".

"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 Expand / Collapse