Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2005-11-11 : 07:29:35
|
| Gary writes "I am creating a simple stored procedure. I want to merge data from 3 tables.1. schedule_rohan = contains hours available in the schedule according to day2. appointments_rohan = contains appointments3. patients_rohan = contains patientsFor example, I have the following as my select statement:SELECT *FROM appointments_rohan JOIN schedule_rohan ON appointments_rohan.st_time=schedule_rohan.hour JOIN patients_rohan ON appointments_rohan.name=patients_rohan.NoDossier WHERE appointments_rohan.cal_date = '5/19/2004' AND schedule_rohan.day = 4 ORDER BY st_time ASCIt only produces a data set by matching the available hours from the schedule for that day of the week to the appointment (st_time) for that date in the appointments table.How can I return a data set that matches the hours in the schedule with the appointments for that day, but also shows a null value for hours that don't have an appointment in the appointments table (appointments_rohan)? It seems that I could use a RIGHT OUTER JOIN, but it doesn't return the data set I want.Thanks,Gary" |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2005-11-11 : 09:12:53
|
you need to have an extra table with all hours you want to show.and then left join to that table.Go with the flow & have fun! Else fight the flow |
 |
|
|
|
|
|