Identify last statement run for a specific SQL Server session
The process to return the last query statement executed is quite straight-forward and works in all versions of Microsoft SQL Server since DMOs (dynamic management objects) were integrated into SQL Server.