• Phil Parkin - Wednesday, February 14, 2018 1:43 PM

    robert693 - Wednesday, February 14, 2018 1:39 PM

    Hi,
    I have a DB with PATIENT_ID, ARRIVAL_DATE, DEPARTURE_DATE, and DEPARTMENT. I need to find the average number of patients in each department per hour over a time frame. So if the date range chosen is 01/01/2018, and the end date chosen is 02/01/2018, then I need to know the average number of patients that were in each department in hours 1:00 to 23:00 over this time period. I have tried several ways but I cannot get this to work Any help would be greatly appreciated!

    Sounds straightforward. You'll get far more responses if you script out some sample data, in consumable format.

    In the meantime, checkout DATEPART in books online. That and GROUP BY will be in your solution I think.

    Best,
    Kevin G. Boles
    SQL Server Consultant
    SQL MVP 2007-2012
    TheSQLGuru on googles mail service