April 12, 2008 at 1:23 pm
In the following select statement, the Appointment and Ailment tables are connected via the AppointmentAilment association table. An appointment could have several ailments associated with it. In this case, I want to be certain that only one Ailment record is selected, so I request the min AppointmentAilmentID record
SELECT f.AppointmentID,t.MedicalCodeID,
f.AilmentID, f.AppointmentAilmentID
FROM
dbo.AppointmentAilment f
INNER JOIN
dbo.Ailment t
ON t.AilmentID=f.AilmentID
WHERE
f.AppointmentAilmentID =
(
SELECT Min(b.AppointmentAilmentID)
FROM
dbo.AppointmentAilment b
WHERE
b.IsPrimary=1
AND
b.AppointmentID=a.AppointmentID
April 12, 2008 at 1:51 pm
nevermind : I found the problem and it's fixed.
Sam
April 12, 2008 at 2:29 pm
So, what was the problem and how did you fix it?
--Jeff Moden
Change is inevitable... Change for the better is not.
April 12, 2008 at 2:59 pm
From looking at the OP, I would guess a last closing paranthesis...
N 56°04'39.16"
E 12°55'05.25"
April 12, 2008 at 8:37 pm
kinda embarrassing but it was the
b.AppointmentID=a.AppointmentID
in the last line. I changed it to
b.AppointmentID=f.AppointmentID
the "f" alias referred back to the AppointmentAilment table. The "a" alias was referring back to another copy of AppointmentID earlier in the statement (I did not post entire query).
Sam
April 12, 2008 at 9:12 pm
Heh... I've made many such a mistake... thanks for the feedback.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply