Talk:Log trigger

Latest comment: 12 years ago by Seehorse

New to Wiki editing. Thought about adding references to this otherwise okay article.

"Database Fundamentals" by Nareej Sharma et. al. (First Edition, Copyright IBM Corp. 2010) for DB2 implementation "Microsoft SQL Server 2008 - Database Development" by Thobias Thernström et. al. (Microsoft Press, 2009) for SQL Server implementation

Also, consider adding a section on FileMaker implementation of Log trigger for tuple versioning as described in the "FileMaker Training Series For FileMaker Pro 11" (2010, FileMaker Inc.). Will include draft in this talk page. Look forward to everyones input and feedback. Thanks. Seehorse (talk) 16:20, 18 December 2011 (UTC)Reply

The last example is actually faulty and will return an empty results set. This query is supposed to return the first entry, but will actually return no results because it is a very inefficient way to return the row where StartDate IS NULL, but that doesn't exist.

SELECT H2.Column1, H2.Column2, ..., H2.Columnn, H2.StartDate
 FROM HistoryTable AS H2 LEFT OUTER JOIN HistoryTable AS H1
   ON H2.Column1 = H1.Column1
  AND H2.Column1 = @KEY
  AND H2.StartDate = H1.EndDate
WHERE H1.EndDate IS NULL

I think the query you were looking for would be.

SELECT H2.Column1, H2.Column2, ..., H2.Column, H2.StartDate
 FROM HistoryTable AS H2 
INNER JOIN
  (SELECT Column1, min(StartDate) as FirstDate 
    FROM HistoryTable 
    WHERE Column1=@KEY 
    GROUP BY Column1 ) AS H1
 ON H2.Column1 = H1.Column1
  AND H2.StartDate = H1.FirstDate