Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>EDIT: I was able to successfully add an AD column! The new problem: The results are a bit off. Before when the results were ranked based on location, each distinct location was assigned a rank based on a total of points. It was clean and the numbers added up. Now there are duplicate ADs and the ranking is backwards (least amount of total ranking points is listed as 1st place).</p> <p>I simply added the AD column to the INSERT statement and the select statements. Can anybody tell me, in addition to adding the AD Column throughout the appropriate locations of the query, should I be modifying any of the operations or functions of the query to reflect a true ranking for the given date range? Please feel free to ask for a clarification on any part of this. Thanks in advance for any assistance you can provide.</p> </blockquote> <p>You'll need AD columns in both your temp tables (#ACS and ##HRRep), and the population of each (i.e. the INSERT INTO.... SELECT FROM) should have the AD column in the GROUP BY. Then your final SELECT will need to join the two tables on the AD column as well as the other columns already in the join expression.</p> <p>I suspect that you don't need the GROUP BY in the final SELECT, as (I <em>think</em>) the two tables already have the results aggregated by areaid, location etc, and RANK() is a single-row function rather than an aggregate like SUM:</p> <pre><code>LEFT JOIN #HRRep AS B ON a.areaid = b.areaid AND a.monthname = b.monthname AND a.location = b.location) a /* Probably don't need this bit GROUP BY a.Location, a.RepResolve, a.RRRank, a.ERP, a.ERPRank,a.HourRepeatPercent, a.RepeatRank, (a.RRRank + a.ERPRank + a.RepeatRank) But this bit: */ ORDER BY (a.RRRank+a.EPRank+a.RepeatRank) DESC </code></pre> <p>Laurence's suggestion of creating a mapping table (he's dared to dive into the "hideousness" inside the first set) is great as it isolates the "hideousness" in one place.</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.
 

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