We have 500 people in the Org. the columns in the table is set up as Name,Report1,Report2,Report3,Report4.
So each person reports to someone i.e. their manager who is in Report1
So Fred Flinstone reports to Barney Rubble who reports to Wilma, who reports to Betty.
Betty is the top
Like so
Name, Report1, Report2,Report3,Report4,
Fred, Barney, Wilma,Betty, NULL
Bam Bam, Barney,Wilma,Betty, NULL
Pebbles,Wilma,Betty, NULL,NULL
I need to get counts of everyone who works under Wilma for example:
So it would Be Fred,Barney,Bam Bam,Pebbles = 4
Under Betty it would be Fred,Barney,Bam Bam,Pebbles,Wilma = 5
So some how I need to loop, but would don't want 4 recursive loops for each report.
Is there a way to set up a SQL statement to do this maybe a WITH
DougP
So each person reports to someone i.e. their manager who is in Report1
So Fred Flinstone reports to Barney Rubble who reports to Wilma, who reports to Betty.
Betty is the top
Like so
Name, Report1, Report2,Report3,Report4,
Fred, Barney, Wilma,Betty, NULL
Bam Bam, Barney,Wilma,Betty, NULL
Pebbles,Wilma,Betty, NULL,NULL
I need to get counts of everyone who works under Wilma for example:
So it would Be Fred,Barney,Bam Bam,Pebbles = 4
Under Betty it would be Fred,Barney,Bam Bam,Pebbles,Wilma = 5
So some how I need to loop, but would don't want 4 recursive loops for each report.
Is there a way to set up a SQL statement to do this maybe a WITH
Code:
WITH MyReport1
AS ( SELECT Name,Manager,Report1,Report2,Report3,Report4
FROM MyTable
Where Report1 = 'Barney Rubble')
(SELECT Name, Report1,Report2,Report3,Report4
FROM MyReport1)
DougP