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.
| Author |
Topic |
|
Mageshkumar
Starting Member
29 Posts |
Posted - 2008-08-04 : 02:59:18
|
| Hi my table is like this:Id Name Mid100 N1 0101 N2 0102 N3 100103 N4 101104 N5 100105 N6 102Now i want based on managers it have to display employees, it mean i need my dataset like this:Managers:Id Name MID100 N1 0101 N2 0Sub Managers:102 N3 100104 N5 100103 N4 101Member:105 N6 102How to write the query for this? |
|
|
dexter.knudson
Constraint Violating Yak Guru
260 Posts |
Posted - 2008-08-04 : 03:50:26
|
| See if this gives you what you need- http://www.eggheadcafe.com/articles/sql_server_recursion_with_clause.asp |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-08-04 : 04:46:34
|
| Also read about Trees and hierarchies in sql server help fileMadhivananFailing to plan is Planning to fail |
 |
|
|
harlingtonthewizard
Constraint Violating Yak Guru
352 Posts |
Posted - 2008-08-04 : 08:45:45
|
| You do have to pay for membership however this site has good quality video that shows you exactly how to do this and much more. Check it out, I have found it very useful.http://www.trainingspot.com/Subscriber/Default.aspxVideo 11.1: Using Common Table Expressions (Example shows how to display hierarchies from top manager down) |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-08-04 : 13:29:25
|
| Have a look at recursive CTE in sql server books online |
 |
|
|
harlingtonthewizard
Constraint Violating Yak Guru
352 Posts |
Posted - 2008-08-05 : 00:18:49
|
| Here is the example:http://blog.sqlauthority.com/2008/07/28/sql-server-simple-example-of-recursive-cte/ |
 |
|
|
|
|
|