How to display the first and second Doctor to see a patient?

  • I have to create a table where there are lots of columns pulling date from one table and two views. To display the columns is no problem. The problem comes into play when I have to alias two columns to show a patient who received services from the first two distinct doctors (doctor_1 and doctor_2). Each doctor has their own ID. I’m not sure if I should use the “distinct top (2)”, “rank”, etc… Here is what it sort of looks like.

    Date, LastName, FirstName, Address, City, State, Zip, Hostital, Room, Doctor_1,Doctor_2

    Any help would be greatly appreciated.

  • Hi,

    One way is "Top 2" of doctors in a subquery and link it to patient table to get your data extract.

    regards

    Natraj

  • Can you confirm that you are using SQL Server 2000?

    Have a quick read of the link "here" in my sig, it will help you frame your question for a better answer.

    “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

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

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