Trying to write a query to display the current status of services in a company department. What I have written is just not working. I feel like I am going in the wrong direction.
SELECT MAX(v_StatusEvents.EventTimeStamp) as EventTimeStamp
, MAX(v_StatusEvents.StatusTypeID) as StatusTypeID
, v_StatusEvents.ServiceID
, v_StatusEvents.StatusTypeDescription
, v_StatusEvents.ServiceName
, v_StatusEvents.CategoryName
FROM v_StatusEvents
WHERE v_StatusEvents.CategoryID = 100
AND YEAR(v_StatusEvents.EventTimeStamp) = YEAR(getdate())
AND MONTH(v_StatusEvents.EventTimeStamp) = MONTH(getdate())
AND DAY(v_StatusEvents.EventTimeStamp) = DAY(getdate())
GROUP BY v_StatusEvents.ServiceID
, v_StatusEvents.StatusTypeDescription
, v_StatusEvents.ServiceName
, v_StatusEvents.CategoryName
I have three CATEGORIES: (100 – Internet, 101 – Applications, and 102 – Network).
Each CATEGORY contains SERVICES.
As an example, I have three SERVICES that belong to the CATEGORY Interenet: (50 – Internal, 51 – External, 52 – Development).
Each SERVICE will always have at least one status record for the current date.
The CURRENT STATUS will be set to one of three different STATUS TYPES values: 1 = no issue, 2 = disruption, 3 = critical.
I want to show the highest STATUS TYPE for each category for today.
Here is a sample record set for today’s date.
SeID CatID EventTimeStamp SvcID StatTypeID
201 100 11/11/2012 12:01am 52 1
202 100 11/11/2012 12:01am 51 1
203 100 11/11/2012 12:01am 50 1
204 100 11/11/2012 08:00am 51 3
205 100 11/11/2012 10:50am 50 2
206 100 11/11/2012 11:00am 50 1
207 100 11/11/2012 11:25am 52 2
As you can see, there was a disruption problem with the Internal web site at 10:50m, but it was resolved at 11:00am.
There is an ongoing critical issue with the External web site that has not yet been resolved. I would like the for the query to return the value 3 because this is the highest CURRENT STATUS for a SERVICE that has not been resolved.
(If all services had “no issue”, I would expect the query to return the value 1)
Thanks,
crjunk
Ended up coming with the following solution:
SELECT (IsNull(MAX(tblStatusTypes.StatusTypeImgURL), (SELECT tblStatusTypes.StatusTypeImgURL FROM tblStatusTypes WHERE tblStatusTypes.StatusTypeID = 1)))
FROM tblStatusTypes
WHERE tblStatusTypes.StatusTypeID in (