| Author |
Topic |
|
chris_cs
Posting Yak Master
223 Posts |
Posted - 2010-06-17 : 11:47:58
|
I'm using the following query to generate a matrix which maps the amount of work our employees do for certain people.SELECT abbreviatedname AS FE, [NKH] AS NKH,[AJF] AS AJF,[CPM] AS CPM,[HGH] AS HGH,[REJ] AS REJ,[PNH] AS PNH,[ACJ] AS ACJ,[BRC] AS BRC,[CJM] AS CJM,[HRG] AS HRG,[CST] AS CST,[SEK] AS SEK,[GJS] AS GJS,[JAW] AS JAW,[RMB] AS RMB,[BPH] AS BPH,[JMB] AS JMB,[CWM] AS CWM,[DMC] AS DMC,[DJW] AS DJW,[GMP] AS GMP,[MDN] AS MDN,[JJC] AS JJC,[SKT] AS SKT,[ECO] AS ECOFROM(SELECT e.abbreviatedname, n.namecode, w.totalunitsFROM WORKHISTORY AS wINNER JOIN EMPLOYEE AS e ON w.EMPLOYEENO=e.EMPLOYEENOINNER JOIN CASES AS c ON c.CASEID=w.CASEIDLEFT OUTER JOIN CASENAME AS cn ON cn.CASEID = c.CASEID AND cn.NAMETYPE IN ('SIG', 'SA')LEFT OUTER JOIN NAME AS n ON n.NAMENO=cn.NAMENOLEFT OUTER JOIN CASENAME AS fe ON fe.CASEID = c.CASEID AND fe.NAMETYPE = 'EMP'LEFT OUTER JOIN NAME AS n3 ON n3.NAMENO=fe.NAMENOWHERE w.TRANSTYPE=400 AND w.TRANSDATE>=DATEADD(DAY,-180 ,GETDATE())AND w.WIPCODE NOT IN ('ZPA', 'ZPD', 'ZERO')) iPIVOT(SUM(totalunits)FOR namecode IN([NKH], [AJF], [CPM], [HGH], [REJ], [PNH], [ACJ], [BRC], [CJM], [HRG], [CST], [SEK], [GJS], [JAW], [RMB], [BPH], [JMB], [CWM], [DMC], [DJW], [GMP], [MDN], [JJC], [SKT], [ECO])) AS pvtORDER BY pvt.abbreviatednameThis is working ok but I have to do one more thing and I'm not sure how to go about it. The X axis will display all of our partners followed by the senior associates in order of seniority, and the Y axis every employee incl partners etc. What I need to do is exclude the units being included when the employee (Y axis) matches the senior associate (BPH onwards on the X axis).Any ideas on this?If this doesn't make any sense at all I can try and think of a better way of explaining it. |
|
|
Devart
Posting Yak Master
102 Posts |
Posted - 2010-06-18 : 07:05:21
|
| Not sure that I understood everything correctly, but try adding WHERE abbreviatedname NOT IN ('NKH', 'AJF', 'CPM', 'HGH', 'REJ', 'PNH', 'ACJ', 'BRC', 'CJM', 'HRG', 'CST', 'SEK', 'GJS','JAW', 'RMB', 'BPH', 'JMB', 'CWM', 'DMC', 'DJW', 'GMP', 'MDN', 'JJC', 'SKT', 'ECO') beforeORDER BY pvt.abbreviatednameDevart, Database tools for SQL Serverhttp://www.devart.com/dbforge/sql |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-06-18 : 12:13:41
|
| can you show sample output of how you want data to displayed?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|