SQL question (DATEDIFF and COUNT)

Posted on 2005-05-04
Last Modified: 2010-03-19
I have a table that holds ServiceTickers that has a  DateEntered and DateResolved columns. I wish to make a stored procedure that returns the difference in days between the two dates and sums up how many have that date difference. I.E. I want to know how many 3-day tickets there are, how many 4-day etc.

Question by:RuralInstitute
    1 Comment
    LVL 28

    Accepted Solution

    Try this:

    SELECT DATEDIFF(DD, DateEntered, DateResolved), COUNT(*)
    FROM YourTable
    GROUP BY DATEDIFF(DD, DateEntered, DateResolved)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
    Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
    Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
    Viewers will learn how the fundamental information of how to create a table.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now