All,
Been rattling my brains out on getting this query to return the proper results...
Would like to return two records for each "FileNo" that has X300 and X400 for the same date. If a FileNo does not have both a X300 and X400 for the same date, do not return anything for that FileNo.
Table Example
FileNo Date Code
TEST1 2007-11-30 X300
TEST1 2007-11-30 X400
TEST2 2007-11-30 X300
Result I am looking for.
TEST1 2007-11-30 X300
TEST1 2007-11-30 X400
(TEST2 would not be returned.)
I was using this as a starting point...
SELECT Activity1.*
FROM Activity1
INNER JOIN (SELECT FileNo, Code, Max(Date) AS Date
FROM Activity1
GROUP BY FileNo, Code) Tbl1
ON Activity1.Code = Tbl1.Code AND
Activity1.FileNo = Tbl1.FileNo AND
Activity1.Date = Tbl1.Date
WHERE Activity1.Code = 'X300'Or Activity1.Code = 'X400'
ORDER BY Activity1.FileNo, Activity1.Code DESC, Activity1.Date
But it only returns the most recent date value.
Thoughts?
Thanks
Rob - KARR
Been rattling my brains out on getting this query to return the proper results...
Would like to return two records for each "FileNo" that has X300 and X400 for the same date. If a FileNo does not have both a X300 and X400 for the same date, do not return anything for that FileNo.
Table Example
FileNo Date Code
TEST1 2007-11-30 X300
TEST1 2007-11-30 X400
TEST2 2007-11-30 X300
Result I am looking for.
TEST1 2007-11-30 X300
TEST1 2007-11-30 X400
(TEST2 would not be returned.)
I was using this as a starting point...
SELECT Activity1.*
FROM Activity1
INNER JOIN (SELECT FileNo, Code, Max(Date) AS Date
FROM Activity1
GROUP BY FileNo, Code) Tbl1
ON Activity1.Code = Tbl1.Code AND
Activity1.FileNo = Tbl1.FileNo AND
Activity1.Date = Tbl1.Date
WHERE Activity1.Code = 'X300'Or Activity1.Code = 'X400'
ORDER BY Activity1.FileNo, Activity1.Code DESC, Activity1.Date
But it only returns the most recent date value.
Thoughts?
Thanks
Rob - KARR