martes, 9 de junio de 2015

Get the lastest 10 records from a Log Table

Here an example of getting the lastest 10 records from a log table.

DECLARE @Rows SMALLINT = 10
DECLARE @logid VARCHAR(10) = 'APP.BANCO'

SELECT [LogId],[Process],[CreatedOn],[Type],[Message]
FROM [dbo].[LogApplication]
WHERE [Process] = @logid
ORDER BY LogId DESC OFFSET 0 ROWS FETCH NEXT @Rows ROWS ONLY