I have two tables, a patient table an and appointment table. I'm attempting to retrieve the information from both tables depending on what doctor is logged in at the time. My stored procedure is as follows:
ALTER PROCEDURE dbo.sprocGetAllAppointmentsForUser
@UserID varchar(50)
AS
SELECT Appts.appt_id, Appts.patient_id, Appts.dr_id, Appts.appt_time, Appts.appt_reason, p.patient_id,
p.patient_first_name, p.patient_last_name, p.patient_addr, p.patient_city, p.patient_zip,
p.patient_state, p.patient_phone, p.patient_healthcare, p.patient_diagnosis, p.patients_user_id
FROM Patients p INNER JOIN Appts
ON Appts.patient_id = p.patients_user_id
WHERE Appts.dr_id = @UserID
RETURN
That should get every appointment and patient information correct? Or am I over simplifying it. Heres some sample data:
Appointment Table:
appt_id patient_id dr_id
1 467 101
2 242 101
3 784 210
Will only return the first row, even though there are two rows corresponding to dr_id 101.