简体   繁体   中英

Pulling the latest instance of a file audit trail in MS SQL

I am trying to simply pull a list of Files that have a certain string in a audit trail that we run internally. When I run this it pulls 0 results, but it should certainly contain a lot more.

use ResWare

SELECT distinct FileID, MAX(AuditID), date
  FROM Audit A
WHERE FileID IN (
SELECT DISTINCT FileID 
  FROM Audit 
 WHERE AuditTypeID = 1 
 and Description = 'File Status: CHANGED from: ''Opened'' to ''Cancelled''' 
 and date between '2013-09-01 00:00:01' and '2013-11-15 23:59:59')
GROUP BY FileID, date
Use ResWare

Select distinct fm.FileNumber, MAX(a.Date), a.FileID
from filemain fm
join status s on s.StatusID = fm.StatusID and s.Name = 'Cancelled'
join audit a on a.FileID = fm.FileID and a.AuditTypeID = 1
where a.Date between '2013-09-01 00:00:01' and '2013-11-15 23:59:59'
and a.Description = 'File status: CHANGED from: ''Open'' to: ''Cancelled'''
and fm.FileNumber not like 'PA-%'
and fm.FileNumber not like 'BNT-PA-%'
and fm.FileNumber not like 'BNT-N%'
and fm.FileNumber not like 'BNT-St%'
group by a.Date, fm.FileNumber, a.FileID

is what I was looking for.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM