I need a little help getting this script doing what I want it to.
SELECT KM.initials,
TPL.debprice,
TMP.pricegroup,
TMP.date
FROM klientmedarbejder KM
INNER JOIN timeprismedarbejderprisgruppe TMP
ON KM.employeeno = TMP.employeeno
INNER JOIN timeprisprisgruppelinie TPL
ON TMP.pricegroup = TPL.pricegroup
GROUP BY KM.initials,
TMP.date,
TPL.debprice,
TMP.pricegroup,
TPL.date
HAVING ( Max(TMP.dato) = TPL.date )
What I need is the debPrice with the latest (max) date. An employee goes through his career, once in a while his price gets upgraded. Price gets selected from a set list of prices.
KlientMedarbejderis the employee table.TimeprisMedarbejderPrisgruppeis the list of date his record get upgrade to the new price.TimeprisPrisgruppeLinieis the list of prices you can have.
I have the solution down to 2 options per employee. Hence:
emp A - 300 - 9 - 1900-01-01
emp A - 500 - 4 - 2012-01-01
emp B - 400 - 6 - 1900-01-01
emp B - 800 - 8 - 2012-04-01
Hence, first record is the default from whenever he joined the company. In 2012 he was finally good enough for a better price tag. Now I need the answer with the latest date on the upgrade list for each employee. Hence emp A should give me 500 and emp B should give me 800. Now not all employees may have had the 01-01 or 04-01 price update. Some employees have had up to 8 upgrades over time, I only care for the latest.
Client I’m pulling this data from is running an SQL Server 2000.
The typical solution for SQL Server 2000 is to isolate the employeeno and their max date (this is much easier in 2005+). Pseudo-code:
The danger is if employeeno + date is not unique, you could get multiple rows, so you need to determine how to deal with ties.
I would write it for your schema but I can’t reverse engineer your query to figure out which table is which. Start simple and work up.