Thanks to everyone, I got it working. For the sake of posterity, here
is what I came up with:
SELECT a.*
FROMappointment a INNER JOIN
(SELECT patient_id, MIN(appointment_date) AS appointment_date
FROM appointment
GROUP BY patient_id, convert(va
Isn't this way easier and executes way faster?
select * from appointment
left join (
select
patient_id,
min(appointment_date) as firstAppt,
datepart(yy,appointment_date),
datepart(dd,appointment_date),
datepart(mm,appointment_date)
from appointment
group by p
I like this approach. That middle query inserting into the temp table
might be what I need for the view.
Thanks,
Judah
On Tue, Feb 24, 2009 at 12:48 PM, wrote:
>
> These sort of queries are always kind of annoying. My approach is to to
> use an intermediate temp table, group by patient and da
This is the sort of approach I was trying to think of, couldn't
remember derived tables. This query only grabs the earliest
appointment for each patient though not the earliest for every day.
But it is a good starting point, I'll try to massage a group by date
in there and see what I can come up w
Maybe
Select top 1 * from appointment where appointment between (date/time and
date/time) order by appointment_date
Ben Conner wrote:
> Hi Judah,
>
> I suppose there's more than one way to do this, but this should work...
>
> SELECT a.*
> FROM appointment a INNER JOIN
>
Hi Judah,
I suppose there's more than one way to do this, but this should work...
SELECT a.*
FROM appointment a INNER JOIN
(SELECT patient_id, MIN(appointment_date)
AS appointment_date
FROM appointment
These sort of queries are always kind of annoying. My approach is to to
use an intermediate temp table, group by patient and day, and find the
min() appointment date. Then join that temp table back to your
appointment table to pull out the rest of the information for that first
appointment based
7 matches
Mail list logo