Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Hierarchical information
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Titre:
Hierarchical information
Divers
Thread ID:
00547813
Message ID:
00547813
Vues:
45
Hello

I have a table named personnel which is defined as below :
create table personnel (
cuid char(10),
cname char(45),
cmanagerid char(10)
)

Sample data is as follows :
1111111111,Mike,2222222222
3333333333,John,1111111111
2222222222,Glen,NULL

Cuid is the unique identification character key which is generated by an indigeneous key generating engine.
cmanagerid is the foreign key linked to personnel.cuid.

What I want to do is as follows :
I want to write an sql statement which returns me a cursor describing the hierarchy of this table. The parameters to be passed are the starting cuid and the number of levels.


For example :
if the parameters are cuid = 3333333333 and level = 3 then cursor must be :
column1 column2 column3
John Mike Glen
or
column1
John
Mike
Glen

if the parameters are cuid = 3333333333 and level = 2 then cursor must be :
column1 column2
John Mike
or
column1
John
Mike

if the parameters are cuid = 1111111111 and level = 2 then cursor must be :
column1 column2
Mike Glen
or
column1
Mike
Glen
or
column1
Mike
Glen
Null


I hope the problem is clear. Is there a way to achive this directly using a sql statement and not using a stored procedure.
However, solutions in both the ways (stored procedure and sql statement) are welcome.

Thanks in anticipation.
Ajay
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform