Query Assistance
- From: t8ntboy <t8ntboy@xxxxxxxxx>
- Date: Thu, 13 Mar 2008 06:07:38 -0700 (PDT)
I have the following query that yields the most recent status for a
record based on both the last date the record was modified and the
status of the record.
I am having trouble with the LEFT OUTER JOIN dbo.SAF2_MtgDaysTimes AS
R ON R.CESAFID portion. It is yielding multiple records from the
MtgDaysTimes table and, in turn, creating duplicates.
How can I modify this query to pull only the most recent MtgDaysTimes
record (based on Max recordID)? I have tried several approaches all
of which produce errors. Could this be done by adding an additional
subquery?
Please advise.
Thanks.
SELECT C.CESAFID, C.Term, C.Subj, C.SubjOther, C.Crse, C.CRN,
C.Course_Title, C.Inst1, C.Inst2, C.NewInstructor, C.CH, C.Dept,
C.Mode, C.Cap, C.Site, C.SiteOther, S.ActionDate, S.Status, S.CESAFID,
S.DepartmentSignature, R.MtgDaysTimeID , F.EID, F.FirstName,
F.LastName FROM dbo.SAFs AS C INNER JOIN dbo.SAF2_Status AS S ON
S.CESAFID = C.CESAFID LEFT OUTER JOIN dbo.SAF2_MtgDaysTimes AS R ON
R.CESAFID=C.CESAFID LEFT OUTER JOIN dbo.Faculty AS F ON F.EID =
C.Inst1 WHERE C.Term=Tvar AND C.Dept='Dvar' AND S.Status IN
('DEPTAPPROVED', 'DEPTMODDETAILS', 'DEPTMODSCHD', 'CEBANNERHOLD',
'CEBANNERSETUP', 'CEPAYINPROGRESS', 'CEPAYRELEASE', 'CESITEREVIEWED',
'DEPTMODCOMP', 'CEMODDETAILS', 'DEPTPPRFRM') AND S.ActionDate =
(SELECT MAX (S1.ActionDate)
FROM dbo.SAF2_Status AS S1
WHERE S1.CESAFID=C.CESAFID AND S1.Status NOT IN ('DEPTRMVLST',
'SAFNOTE'))
ORDER BY C.Subj, C.Crse
.
- Follow-Ups:
- Re: Query Assistance
- From: --CELKO--
- Re: Query Assistance
- Prev by Date: Re: concurrency problem with lists ("check constraint" on groups of rows)
- Next by Date: Re: DateTime Automatic Formatting
- Previous by thread: DDL Trigger To Track Schema Changes
- Next by thread: Re: Query Assistance
- Index(es):
Relevant Pages
|