Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Hierarchical Query

Hi All,

We have CONNNECT BY PRIOR and STARTS WITH commands in ORACLE to query for a hierarchical data..

In MS SQL we don't have any such commands. So how can we achieve this in SQL? If it through stored procedures pls let me know how we can do this in Stored procedures...

Also pls let me know how to combine results sets of two diffrent select statements that returns same type and number of columns...

Any help is greatly appreciated.

TIA

Rgds
Manohar
[516 byte] By [Manohar] at [2007-11-9 21:09:05]
# 1 Re: Hierarchical Query
Hi Manohar,

Microsoft give an example of expanding a hierarchy in their books on-line
included with SQL Server 8. If you have it installed, this link should find
the example:

mk:@MSITStore:C:\Program%20Files\Microsoft%20SQL%20Server\80\Tools\Books\acdata.chm::/ac_8_qd_14_5yk3.htm

To combine two similarly-shaped query results, use UNION or UNION ALL, e.g.

SELECT a, b FROM c
UNION
SELECT d, e FROM f

Hope this helps,
Simon Sellick.

Manohar <manu2679@yahoo.co.uk> wrote:
>Hi All,
>
>
> We have CONNNECT BY PRIOR and STARTS WITH commands in ORACLE to query
for a hierarchical
>data..
>
>In MS SQL we don't have any such commands. So how can we achieve this in
SQL? If it
>through stored procedures pls let me know how we can do this in Stored procedures...
>
>
>Also pls let me know how to combine results sets of two diffrent select
statements that
>returns same type and number of columns...
>
>Any help is greatly appreciated.
>
>TIA
>
>Rgds
>Manohar
Simon Sellick at 2007-11-11 23:54:30 >