Count of Total Appointments within 30 days of each Appointment Date

  • Good Afternoon.

    I have a Table where each Record:

    1) Represents an Appointment.

    2) Has a field Appointment Date.

    What I am trying to achieve is this: For each Appointment date in the dataset I wish to count up all the Appointments which occur within 30 days. For example, for 1st July 2024, I wish to have a total count of all appointments which occurred between 1st July 2024 and 30th July 2024 (and assign this count to 1st July 2024).

    And then continue this process for each Appointment Date within the Dataset.

    Kind Regards

     

    • This topic was modified 16 hours, 54 minutes ago by  Reh23.
  • Please don't cross post.  It tends to fragment the discussion.

    Please respond to this post https://www.sqlservercentral.com/forums/topic/count-of-total-appointments-within-30-days-of-each-appointment-date

    Drew

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Example list of appointment dates from the Appointments Table (many records will have identical Appointment Date) as multiple clients will have appointments on the same day to each other:

    Expected Output for 1st and 2nd July 2024 (assuming we are interested in appointments within 3 days - rather than 30 days as the case in my real-life problem I am working on):

     

  • Just to be sure... you're in an SQL Server 7/2000 forum... which release of SQL Server are you actually using?

    And, yeah... It's really important because there's a whole lot missing in 7/2000 compared to recent releases.

     

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply