This is running on SQL Server 2000
Background: when a new server is brought onto the network, it will pass through a series of status (stages) such as (loading, testing, configuring, production, etc) were production is the final step (not every server in the report will be in production so this bit of information may be a moot point).
I inherited this so if there are any questions, I’ll answer them as best as I can. I’m trying to run a query to get the latest status of all the servers during a specific time frame. My query is currently returning every status for the server and I only need the current status and that is where I need your help.
The query I’m working with is as follows:
SELECT SD.ProjectName, SD.SystemName, SD.Status, H.history_id
FROM dbo.SI_SystemDetail AS SD
INNER JOIN dbo.SI_Projects AS P ON SD.ProjectName = P.ProjectName
INNER JOIN dbo.SI_StatusHistory AS H ON SD.SystemName = H.SystemName
WHERE
(P.Cancelled = 'N')
AND (P.Platform LIKE '%ibm%')
AND ('20110101' <= CONVERT(varchar(8), H.EffectiveDate, 112))
AND (CONVERT(varchar(8), H.EffectiveDate, 112) <= '20111111')
ORDER BY
H.history_id DESC, SD.SystemName, SD.ContactSBCuid, SD.ActualLiveDAte DESC,
SD.ProjectName, SD.SystemType, H.EffectiveDate`
This will return several duplicates for systemname but I only need one and that should correspond with the highest history_id number. For example, lets say there is a server named:
Server Name Status History_ID
Server01 Loading 1001
Server01 Configuring 1081
Server01 Testing 1101
Server01 Production 1451
Server02 Loading 1002
Server02 Configuring 1083
Server02 Testing 1104
Server02 Failed 1455
I would just need the following results returned:
Server Name Status History_ID
Server01 Production 1451
Server02 Failed 1455
Thanks in advance for the assistance.
UNTESTED: