Note that there are some explanatory texts on larger screens.

plurals
  1. POCOLDFUSION: How to GROUP by the first column and convert second column into three separate columns
    primarykey
    data
    text
    <p>This is a sample of the RAW DATA that I working with from the "employeeRatings" Table before the cfquery output:</p> <pre><code> (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 </code></pre> <p>Here's the cfquery (SQL statement):</p> <pre><code>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 </code></pre> <p>After the cfquery, the output will look like this:</p> <pre><code>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 </code></pre> <p>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:</p> <pre><code>supplierID | LastRating | SecondLastRating | ThirdLastRating ====================================================================== 1128 | 30 | 60 | 90 7310000 | 95 | 85 | 75 444981 | 27 | 77 | 97 </code></pre> <p>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!!!!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload