• Hi Sharon

    To help us to help you, can you please set up a data script? You will want to include a minimum of two patients and a minimum of three visits each. Include the data you have already published.

    Your script should consist of a CREATE TABLE statement and an INSERT to populate the table. Be sure to test it before posting.

    I’m sure that what you are asking for is fairly straightforward, but without sample data we’d be pinning the tail on the donkey.

    Cheers

    ChrisM

    “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden