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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Simple Data Merge

Author  Topic 

gisaac
Starting Member

1 Post

Posted - 2005-11-10 : 21:29:45
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 day
2. appointments_rohan = contains appointments
3. patients_rohan = contains patients

For 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 ASC

It 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

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-11-11 : 00:12:27
Post table structures, some sample data and the result you want

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -