• Matt,

    Since you're new here, I'm going to help you out and show you how to post a question so as to get a decent answer. Articles abound throughout the forum that describe this ("forum ettiquette") but here goes.

    First, you need to provide some DDL. It seems in this case that you're giving us sample data that results from your stated query, but you still need to concoct a table format to put it in.

    CREATE TABLE #Skills

    (

    VP VARCHAR(20)

    ,AVP VARCHAR(20)

    ,Director VARCHAR(20)

    ,Supervisor VARCHAR(20)

    ,Worker VARCHAR(20)

    ,File_NBR INT

    ,Skill CHAR(2)

    ,SCORE INT

    );

    Next you need to give us consumable sample data, which together with the above should run in SSMS without need to make modifications to it.

    INSERT INTO #Skills

    SELECT 'Gerald','Kris','Doris',NULL,'Mack',107812,'B2',4

    UNION ALL SELECT 'Gerald','Kris','Doris',NULL,'Mack',107812,'D1',3

    UNION ALL SELECT 'Gerald','Kris','Doris',NULL,'Mack',107812,'D2',3

    UNION ALL SELECT 'Gerald','Kris','Doris',NULL,'Mack',107812,'D3',3

    UNION ALL SELECT 'Gerald','Kris','Doris',NULL,'Mack',107812,'E1',4

    UNION ALL SELECT 'Gerald','Kris','Mike',NULL,'Brady',109080,'A1',5

    UNION ALL SELECT 'Gerald','Kris','Mike',NULL,'Brady',109080,'B1',4

    UNION ALL SELECT 'Gerald','Kris','Mike',NULL,'Brady',109080,'B2',3

    UNION ALL SELECT 'Gerald','Kris','Mike',NULL,'Brady',109080,'B3',4

    UNION ALL SELECT 'Gerald','Kris','Mike',NULL,'Brady',109080,'C1',4

    UNION ALL SELECT 'Gerald','Kris','Mike',NULL,'Brady',109080,'C2',4

    UNION ALL SELECT 'Gerald','Kris','Mike',NULL,'Brady',109080,'C3',0

    UNION ALL SELECT 'Kim','Harry',NULL,'Grant','Tom',108457,'B1',4

    UNION ALL SELECT 'Kim','Harry',NULL,'Grant','Tom',108457,'B2',4

    UNION ALL SELECT 'Kim','Harry',NULL,'Grant','Tom',108457,'C1',4

    UNION ALL SELECT 'Kim','Harry',NULL,'Grant','Tom',108457,'C2',5

    UNION ALL SELECT 'Kim','Harry',NULL,'Grant','Tom',108457,'C5',5

    UNION ALL SELECT 'Kim','Harry',NULL,'Grant','Tom',108457,'D1',4

    UNION ALL SELECT 'Kim','Harry',NULL,'Grant','Tom',108457,'D2',5

    UNION ALL SELECT 'Kim','Harry',NULL,'Grant','Tom',108457,'D3',4

    UNION ALL SELECT 'Kim','Harry',NULL,'Grant','Jean',106934,'C5',4

    UNION ALL SELECT 'Kim','Harry',NULL,'Grant','Jean',106934,'D1',5

    UNION ALL SELECT 'Kim','Harry',NULL,'Grant','Jean',106934,'D3',5

    UNION ALL SELECT 'Kim','Harry',NULL,'Grant','Raphe',108901,'B2',5

    UNION ALL SELECT 'Kim','Harry',NULL,'Grant','Raphe',108901,'C2',5

    UNION ALL SELECT 'Kim','Harry',NULL,'Grant','Raphe',108901,'C3',4

    UNION ALL SELECT 'Kim','Harry',NULL,'Grant','Raphe',108901,'C5',5

    UNION ALL SELECT 'Kim','Harry',NULL,'Grant','Raphe',108901,'D2',5

    UNION ALL SELECT 'Kim','Harry',NULL,'Grant','Raphe',108901,'E1',5

    UNION ALL SELECT 'Kim','Harry',NULL,'Grant','Tyika',107923,'B1',5

    UNION ALL SELECT 'Kim','Harry',NULL,'Grant','Tyika',107923,'B2',5

    UNION ALL SELECT 'Kim','Harry',NULL,'Grant','Tyika',107923,'D2',4

    UNION ALL SELECT 'Kim','Harry',NULL,'Grant','Tyika',107923,'D3',4;

    Then, some nice volunteer is bound to come along and suggest a solution. The one below does an UNPIVOT using the CROSS APPLY VALUES approach (see my signature links for an article on how this works) and then uses a cross tab query to consolidate the results.

    SELECT Name, [Role], b.Skill

    ,[0 Scores]=COUNT(CASE WHEN b.SCORE = 0 THEN 1 END)

    ,[0 Scores Pct Of]=100.*COUNT(CASE WHEN b.SCORE = 0 THEN 1. END)/COUNT(*)

    ,[1 Scores]=COUNT(CASE WHEN b.SCORE = 1 THEN 1 END)

    ,[1 Scores Pct Of]=100.*COUNT(CASE WHEN b.SCORE = 1 THEN 1. END)/COUNT(*)

    ,[2 Scores]=COUNT(CASE WHEN b.SCORE = 2 THEN 1 END)

    ,[2 Scores Pct Of]=100.*COUNT(CASE WHEN b.SCORE = 2 THEN 1. END)/COUNT(*)

    ,[3 Scores]=COUNT(CASE WHEN b.SCORE = 3 THEN 1 END)

    ,[3 Scores Pct Of]=100.*COUNT(CASE WHEN b.SCORE = 3 THEN 1. END)/COUNT(*)

    ,[4 Scores]=COUNT(CASE WHEN b.SCORE = 4 THEN 1 END)

    ,[4 Scores Pct Of]=100.*COUNT(CASE WHEN b.SCORE = 4 THEN 1. END)/COUNT(*)

    ,[5 Scores]=COUNT(CASE WHEN b.SCORE = 5 THEN 1 END)

    ,[5 Scores Pct Of]=100.*COUNT(CASE WHEN b.SCORE = 5 THEN 1. END)/COUNT(*)

    FROM #Skills a

    CROSS APPLY (

    VALUES ('VP', VP, File_NBR, Skill, SCORE)

    ,('AVP', AVP, File_NBR, Skill, SCORE)

    ,('Director', Director, File_NBR, Skill, SCORE)

    ,('Supervisor', Supervisor, File_NBR, Skill, SCORE)

    --,('Worker', Worker, File_NBR, Skill, SCORE)

    ) b([Role], Name, File_NBR, Skill, SCORE)

    WHERE Name IS NOT NULL

    GROUP BY Name, [Role], b.Skill;

    GO

    DROP TABLE #Skills;

    Now, I am not saying this is 100% the solution to your problem but it may get you close. Please let us know if this helped you.


    My mantra: No loops! No CURSORs! No RBAR! Hoo-uh![/I]

    My thought question: Have you ever been told that your query runs too fast?

    My advice:
    INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
    The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.

    Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
    Since random numbers are too important to be left to chance, let's generate some![/url]
    Learn to understand recursive CTEs by example.[/url]
    [url url=http://www.sqlservercentral.com/articles/St