x

List all consultants and their managers

I am able to extract all the information required but not getting managers in the resultset. My resultset lists all consultants, but not who their managers are

 SELECT   Consultant.ConsultantID
 , Consultant.FirstName
 , Consultant.LastName
 , cast(StartDate as date) [Start Date]
 , Consultant.CareerLevel, Sales.RetailSales
 , Sales.RetailSalesTotal
 , Sales.Unit
 , Unit.UnitName
 ,Consultant.AccountStatus
 , CareerLevel.CareerLevelName --lists if consultant or manager
 
 FROM         Consultant INNER JOIN
                       Sales ON Consultant.ConsultantID = Sales.ConsultantID 
                       INNER JOIN Unit ON Consultant.UnitID = Unit.UnitID
                       INNER JOIN CareerLevel 
                          ON CareerLevel.CareerLevelID = Consultant.CareerLevelID
 WHERE Startdate between '01/01/2010' and '12/31/2012'
       
more ▼

asked Sep 28, 2012 at 09:22 PM in Default

avatar image

natongm
308 19 27 31

How would you know who is the manager of a consultant. Your query contains no tracks of a ManagerID (or similar) column, nor did you post any DDL for your tables, so it's hard to tell.

On a more conceptual note: Look at recursive CTEs.

Sep 30, 2012 at 11:42 AM Magnus Ahlkvist

CareerLevelID determines if a consultant is a director or not. So, I am looking to display the names of directors as well as the consultants below them. CareerLevel 6+ is director

Oct 01, 2012 at 03:59 PM natongm

CareerLevelID determines if director or not. CareerLevelID of 6 and up is director level. CareerLevelID is a flag in Consultant table.

Oct 01, 2012 at 04:07 PM natongm

Table schemas would be helpful here. For example why would a manager be listed in a consultant table? It doesn't make a lot of sense.

Oct 01, 2012 at 07:58 PM SirSQL

Ok. So now we know who is à director. But My question was about the relation a consultant has to à director. How do one know which director is Consultant A:s manager?

Oct 02, 2012 at 06:24 AM Magnus Ahlkvist
(comments are locked)
10|1200 characters needed characters left

1 answer: sort voted first

Below is a rudimentary table schemas of CareerLevel and Consultant. Any consultant who has a careerlevel of 6 or more is a director and has other consultants under him/her

CareerLevel Table

CareerLevelID int

CareerLevel int

CareerLevelName varchar

Consultant Table

ConsultantID int

Consultant varchar

CareerLevel int (if consultant careerlevel >= 6, then consultant is director)

IsDirector int

Firstname

LastName

more ▼

answered Oct 02, 2012 at 03:16 PM

avatar image

natongm
308 19 27 31

Below is a rudimentary table schemas of CareerLevel and Consultant. Any consultant who has a careerlevel of 6 or more is a director and has other consultants under him/her

CareerLevel Table

CareerLevelID int

CareerLevel int

CareerLevelName varchar

Consultant Table

ConsultantID int

Consultant varchar

CareerLevel int (if consultant careerlevel >= 6, then consultant is director)

IsDirector int

Firstname

LastName

Oct 02, 2012 at 03:39 PM natongm
(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.

Topics:

x1067

asked: Sep 28, 2012 at 09:22 PM

Seen: 568 times

Last Updated: Oct 02, 2012 at 03:39 PM

Copyright 2016 Redgate Software. Privacy Policy