This is a sample of the RAW DATA that I working with from the "employeeRatings" Table before the cfquery output:
(showcasing employeeID:1128 for the month of May)
employeeID | Possible_Factor | Factor | ratingDate
=======================================================================
1128 | .1 | .1 | 5/25/2013 2:05:13 PM
1128 | .1 | .0 | 5/22/2013 9:30:43 AM
1128 | .2 | .1 | 5/17/2013 9:42:09 AM
1128 | .1 | .1 | 5/13/2013 8:07:15 AM
1128 | .1 | .0 | 5/10/2013 7:52:51 AM
1128 | .4 | .0 | 5/6/2013 12:41:12 PM
Here's the cfquery (SQL statement):
SELECT ROUND(100 * (SUM(Factor) / SUM(Possible_Factor)), 2) AS employeeRating, CONVERT(CHAR(4), ratingDate, 100) + CONVERT(CHAR(4), ratingDate, 120) AS month, employeeID, DATEADD(MONTH, DATEDIFF(MONTH, 0, ratingDate), 0) AS shortdate
FROM employeeRatings
GROUP BY CONVERT(CHAR(4), ratingDate, 100) + CONVERT(CHAR(4), ratingDate, 120), DATEADD(MONTH, DATEDIFF(MONTH, 0, ratingDate), 0), employeeID
ORDER BY employeeID, DATEADD(MONTH, DATEDIFF(MONTH, 0, ratingDate), 0) DESC
After the cfquery, the output will look like this:
employeeID | employeeRating | month | shortdate
=======================================================================
1128 | 30 | May 2013 | 5/1/2013 12:00:00 AM
1128 | 60 | April 2013 | 4/1/2013 12:00:00 AM
1128 | 90 | Jan 2013 | 1/1/2013 12:00:00 AM
7310000 | 95 | April 2013 | 4/1/2013 12:00:00 AM
7310000 | 85 | Mar 2013 | 3/1/2013 12:00:00 AM
7310000 | 75 | Feb 2013 | 2/1/2013 12:00:00 AM
7310000 | 55 | Jan 2013 | 1/1/2013 12:00:00 AM
444981 | 27 | Mar 2013 | 3/1/2013 12:00:00 AM
444981 | 77 | Jan 2013 | 1/1/2013 12:00:00 AM
444981 | 97 | Nov 2012 | 11/1/2012 12:00:00 AM
444981 | 37 | Sept 2012 | 9/1/2012 12:00:00 AM
444981 | 47 | Aug 2012 | 8/1/2012 12:00:00 AM
I need to take an employee and list their LAST THREE ratings (if month is null, skip the null month and get the next month with a rating in order to showcase last three documented ratings). This is a dynamic cfquery that list over 200 employees. The following is the desired output:
supplierID | LastRating | SecondLastRating | ThirdLastRating
======================================================================
1128 | 30 | 60 | 90
7310000 | 95 | 85 | 75
444981 | 27 | 77 | 97
I am using ColdFusion on a SQL Server 2000 (compatibility 80), however the ColdFusion version I am using do not support cfloop group attribute. I would like to take the new output and put it into a new query, so it can be JOINED with another query. A solution = starbucks gift from FB ;) Thank you everyone for your time and consideration!!!!