Hi all
It was suggested to me to use the following SQL statement
select Access."Key", UserKey, Access, Advised
from access
where (UserKey, Access."Key" in (select UserKey, max(Access."key"
from access
group by UserKey)
order by UserKey
to get the following result:
Will show:
142, 12, FI83P10, 2002/01/01
143, 13, Spandial, 2000/01/01
145, 14, IDIR, 2001/01/01
Because they are the latest records with each userkey where 'Key' is the max value of each set of records.
from table:
Key, UserKey, Access, Advised
140, 12, FI83P10, 2000/01/01
141, 12, FI83P10, 2001/01/01
142, 12, FI83P10, 2002/01/01
143, 13, Spandial, 2000/01/01
144, 14, IDIR, 2000/01/01
145, 14, IDIR, 2001/01/01
I tried:
strSQL := 'SELECT Max(Access."Key", UserKey, Access, Access."Transaction", Actioned, ActionedBy, Completed, CompletedBy, Advised, AdvisedBy, Clientele ';
AppendStr(strSQL, 'FROM Access ');
AppendStr(strSQL, 'Where UserKey = ' + IntToStr(DM.AccountsKey.Value));
AppendStr(strSQL, 'GROUP BY Access."Key", UserKey, Access, Access."Transaction", Actioned, ActionedBy, Completed, CompletedBy, Advised, AdvisedBy, Clientele ');
AppendStr(strSQL, 'ORDER BY Access ');
but it is not working. Any Delphi 4 SQL gurus out there have any ideas?
Thanks
James
It was suggested to me to use the following SQL statement
select Access."Key", UserKey, Access, Advised
from access
where (UserKey, Access."Key" in (select UserKey, max(Access."key"
from access
group by UserKey)
order by UserKey
to get the following result:
Will show:
142, 12, FI83P10, 2002/01/01
143, 13, Spandial, 2000/01/01
145, 14, IDIR, 2001/01/01
Because they are the latest records with each userkey where 'Key' is the max value of each set of records.
from table:
Key, UserKey, Access, Advised
140, 12, FI83P10, 2000/01/01
141, 12, FI83P10, 2001/01/01
142, 12, FI83P10, 2002/01/01
143, 13, Spandial, 2000/01/01
144, 14, IDIR, 2000/01/01
145, 14, IDIR, 2001/01/01
I tried:
strSQL := 'SELECT Max(Access."Key", UserKey, Access, Access."Transaction", Actioned, ActionedBy, Completed, CompletedBy, Advised, AdvisedBy, Clientele ';
AppendStr(strSQL, 'FROM Access ');
AppendStr(strSQL, 'Where UserKey = ' + IntToStr(DM.AccountsKey.Value));
AppendStr(strSQL, 'GROUP BY Access."Key", UserKey, Access, Access."Transaction", Actioned, ActionedBy, Completed, CompletedBy, Advised, AdvisedBy, Clientele ');
AppendStr(strSQL, 'ORDER BY Access ');
but it is not working. Any Delphi 4 SQL gurus out there have any ideas?
Thanks
James