Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Is Connect BY Clause present in SQL Server ?

Author  Topic 

kiran.moily
Starting Member

2 Posts

Posted - 2007-02-16 : 07:04:48
Hi,

We need to create a tree stucture output of a query.
In case of Oracle , there is 'CONNECT BY' Clause for creating the same.

Does SQL server support anything of this sort?

If yes, can anybody please provide the syntax for the same?

Regards
Kiran

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-02-16 : 07:09:39
No, there is not.
Either do a recursice algorithm, or write a loop to iterate all nodes.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

kiran.moily
Starting Member

2 Posts

Posted - 2007-02-16 : 07:48:49
Is there any other way in SQL Server to get a hierarchical output from a table where parent - child relationships are stored as below:

Parent 1--------Child 1
Parent 1--------Child 2
Parent 1--------Child 3
Child 1---------Child 11
Child 1---------Child 12
Child 2---------Child 21
Child 2---------Child 22
Child 2---------Child 23
Child 2---------Child 24

Regards

Kiran
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-02-16 : 08:11:52
[url]http://www.nigelrivett.net/SQLTsql/RetrieveTreeHierarchy.html[/url]

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2007-02-16 : 08:34:48
Are you using SQL 2005? If so, recursive queries are very easy. A quick google of "sql server 2005 recursive query" gave at least one good example: http://www.databasejournal.com/features/mssql/article.php/10894_3502676_2

If you are using SQL < 2005, it's a little more difficult.



- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page
   

- Advertisement -