Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8854665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:56:10+00:00 2026-06-14T13:56:10+00:00

Trying to write a query to display the current status of services in a

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T13:56:12+00:00Added an answer on June 14, 2026 at 1:56 pm

    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 (

    SELECT MAX(StatusTypeID)
    FROM
    (   SELECT vse.StatusTypeID, vse.ServiceID, vse.EventTimeStamp
        FROM v_StatusEvents vse,
            (SELECT MAX(EventTimeStamp)AS MaxDate
                ,ServiceID
            FROM   v_StatusEvents 
            WHERE  EventTimeStamp >= Cast(Cast(CURRENT_TIMESTAMP AS DATE) AS DATETIME) 
            AND CategoryID = @CategoryID
            GROUP  BY ServiceID) MaxResults
        WHERE vse.ServiceID = MaxResults.ServiceID
        AND vse.EventTimeStamp = MaxResults.MaxDate
    ) MaxStatusType )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a query I don't want to have Cartesian products on.
Alright, I'm trying to write a query to display all the tables that contain
I have a SQL Query which I am trying to write and am now
Im trying to write a query that will find and display all of my
I am trying to write a view/SQLAlchemy query that will allow me to display
Consider following table. I'm trying to write a query to display - Max values
I am trying write a query that will display if the person has anyone
I am trying to write a query to display manager no. and the lowestwages
I am trying to write a query to display to a data control. I'm
I'm trying to write a query that reports the current database activity. The query

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.