Home Forums SQL Server 7,2000 T-SQL Getting the last entry based on a previous entry. RE: Getting the last entry based on a previous entry.

  • SELECT R1.Report_ID, R1.[ReportHistoryID], R1.modified_by, R1.last_modified, R2.[ReportHistoryID], R2.modified_by, R2.last_modified

    FROM [dbo].[Reporthistory] R1

    INNER JOIN (SELECT report_ID, MAX(last_modified) LastModified

    From [dbo].[Reporthistory]

    WHERE Report_status_id = 2

    GROUP BY report_ID

    ) RLM ON RLM.report_ID = R1.report_ID

    INNER JOIN [dbo].[Reporthistory] R2 ON R2.report_ID = RLM.report_ID AND R2.last_modified = RLM.LastModified

    R1.[Report_status_id] = 1

    _____________
    Code for TallyGenerator