Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Hi,I have an audit table thats contains dates when an item was audited.I am currently displaying all items that have an audit date greater than a year old.However, I would like it so that each item would display a single record where its date(ts) is greater than a year by itemID.Can anyone help please?
SELECT max(ts) as ts, ItemID, AuditIDFROM tblAuditWHERE (ts < DATEADD(year, - 1, GETDATE()))group by ItemID, AuditIDMadhivananFailing to plan is Planning to fail
feelingsheepish
Starting Member
8 Posts
Posted - 2009-09-07 : 11:08:26
This still returns several records for a single ItemID.I would like to display only the most recent date for each ItemIDThanks
feelingsheepish
Starting Member
8 Posts
Posted - 2009-09-07 : 11:22:59
Got this working now:
SELECT MAX(tblAudit.ts) AS ts, tblAudit.ItemID, tblItem.ItemNoFROM tblAudit INNER JOIN tblItem ON tblAudit.ItemID = tblItem.ItemIDWHERE (tblAudit.ts < DATEADD(year, - 1, GETDATE()))GROUP BY tblAudit.ItemID, tblItem.ItemNo