Query Help

For complex topics that regular users would not be interested in. For power users and database administrators.
Post Reply
atd
Posts: 404
Joined: Thu Mar 27, 2008 2:28 pm
Location: Minneapolis, MN

Query Help

Post by atd » Tue Dec 16, 2008 2:47 pm

I'm trying to figure out a query similar to the planned appt tracker list. The difference is that I'm subtotalling the planned appointments, with specific Unscheduled statuses, for each public health site. What I'm missing is how to exclude the planned appointments that are already scheduled. I'm sure it's simple, but I'm new at this. Here's what I have so far:

SELECT site.Description, COUNT(appointment.PatNum) as Patients, SUM(appointment.IsHygiene) as HygAppt FROM appointment
LEFT JOIN patient ON appointment.PatNum=patient.PatNum
LEFT JOIN site ON patient.SiteNum=site.SiteNum
WHERE appointment.AptStatus=6 AND patient.ClinicNum=1 AND (appointment.UnSchedStatus=0 OR appointment.UnSchedStatus=420 OR appointment.UnSchedStatus=428)
GROUP BY patient.SiteNum

If anyone can point me in the right direction I'd appreciate it!

User avatar
jordansparks
Site Admin
Posts: 5770
Joined: Sun Jun 17, 2007 3:59 pm
Location: Salem, Oregon
Contact:

Re: Query Help

Post by jordansparks » Wed Dec 17, 2008 7:56 pm

appointment.NextAptNum contains a foreign key to the planned appt. So...
AND NOT EXISTS (SELECT * FROM appointment aptSched WHERE aptSched.NextAptNum=appointment.AptNum)
Jordan Sparks, DMD
http://www.opendental.com

atd
Posts: 404
Joined: Thu Mar 27, 2008 2:28 pm
Location: Minneapolis, MN

Re: Query Help

Post by atd » Thu Dec 18, 2008 6:15 am

Perfect, thanks for your help.

Post Reply