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 |
|
swathigardas
Posting Yak Master
149 Posts |
Posted - 2008-11-03 : 05:04:52
|
| Hi i have tables - Employee_skill, Rating, Skill, Employee, Employee_Project,Projectas shown belowEmployee_skillSkill_NBR Employee_nbr supervisor rating Date1 1 3 01/01/20072 1 4 08/01/20073 5 2 02/10/200712 2 4 02/10/200712 2 3 02/10/20075 8 4 01/08/20083 1 4 25/10/20082 1 5 25/10/2008RatingNumber Name1 No Experience2 Beginner3 Intermediate4 Proficient5 ExpertSkillNumber Name1 .Net2 SQL3 Java4 Manual Testing12 SiebelEmployeeNumber Name1 Jhon2 Smith3 Vernoica4 Sing5 SonyEmployee_ProjectEmployee_NBR Project_NBR 1 12 13 14 25 2ProjectNumber Name Start_Date End_DT1 PIS 10/1/2008 NULL2 G441 2/15/2007 10/5/2008The above data states that Project G441 is finished and the employees who were allocated to that project are now on bench and the other 3 employees are on job(project).Now to the stored Procedure, I would get From Date and to date as Input parametersAnd I need to display the data as belowSKILL No.of emp with this skill set current job total employees on bench.Net 1 1 0SQL 1 1 0Java 1 1 1Siebel 1 1 0Can anyone help me thru this Stored Procedure.Thanks in advance |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-11-03 : 06:03:09
|
| [code]SELECT s.Skill,COUNT(DISTINCT es.Employee_nbr ) AS TotalEmployeeswithSkill,COUNT(DISTINCT CASE WHEN p.Number IS NOT NULL THEN es.Employee_nbr ELSE NULL END ) AS ToatlEmployeesCurrentlyInProj,COUNT(DISTINCT CASE WHEN p.Number IS NULL THEN es.Employee_nbr ELSE NULL END ) AS ToatlEmployeesInBenchFROM Employee_skill esINNER JOIN Rating rON r.Number =es.rating INNER JOIN Skill sON s.Number =es.Skill_NBRINNER JOIN Employee eON e.Number =es.Employee_nbr INNER JOIN Employee_Project epON ep.Employee_NBR = es.Employee_nbr LEFT JOIN Project pON p.Number =ep.Project_NBRAND p.End_DT IS NOT NULLGROUP BY s.Skill[/code] |
 |
|
|
swathigardas
Posting Yak Master
149 Posts |
Posted - 2008-11-03 : 08:45:23
|
hey thanks vishakh... but i've slightly modified it to p.END_DT IS NULL in the second case statement which actually gave me a proper result.Thanks a lot for the needful. I need to insert more data and check it again. Will get back if i wont get the desired output.thanks again  quote: Originally posted by visakh16
SELECT s.Skill,COUNT(DISTINCT es.Employee_nbr ) AS TotalEmployeeswithSkill,COUNT(DISTINCT CASE WHEN p.Number IS NOT NULL THEN es.Employee_nbr ELSE NULL END ) AS ToatlEmployeesCurrentlyInProj,COUNT(DISTINCT CASE WHEN p.Number IS NULL THEN es.Employee_nbr ELSE NULL END ) AS ToatlEmployeesInBenchFROM Employee_skill esINNER JOIN Rating rON r.Number =es.rating INNER JOIN Skill sON s.Number =es.Skill_NBRINNER JOIN Employee eON e.Number =es.Employee_nbr INNER JOIN Employee_Project epON ep.Employee_NBR = es.Employee_nbr LEFT JOIN Project pON p.Number =ep.Project_NBRAND p.End_DT IS NOT NULLGROUP BY s.Skill
|
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-11-03 : 09:17:49
|
You're welcome Let me know if you face any more issues. |
 |
|
|
|
|
|
|
|