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 |
abhit_kumar
Posting Yak Master
147 Posts |
Posted - 2011-09-20 : 03:10:18
|
Dear ALL Experts,I want a query in the following scenario, please help me.For Example:-There are four Employee i.e Emp A, Emp B, Emp C, Emp Dnow everone have their sales figures i.eEmp A = 1000Emp B = 3000Emp C = 400Emp D = 5000Now the Emp C, Emp D is reporting to Emp B, and Emp B is reporting to Emp A.So when i want total sales figure of Emp B then its should be:- Emp B = Emp B + Emp C + Emp Dwhen i want total sales figure of Emp A, then its should be :- Emp A= Emp A + Emp B + Emp C + Emp DI have created a table also, where C and D is reporting to B and B is reporting to A.Please guide me.Regards,AKM |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-09-20 : 03:12:50
|
how is hierarchy set up in table? can you show table structure with some sample data?if its properly setup you can use a recursive CTE to achieve this------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
abhit_kumar
Posting Yak Master
147 Posts |
Posted - 2011-09-20 : 04:34:37
|
empid empname managerid managername1 emp a 2 emp b 1 emp a3 emp c 2 emp b4 emp d 2 emp b quote: Originally posted by visakh16 how is hierarchy set up in table? can you show table structure with some sample data?if its properly setup you can use a recursive CTE to achieve this------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
|
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
abhit_kumar
Posting Yak Master
147 Posts |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-09-20 : 05:46:15
|
welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
|
|
|