Create PROCEDURE [dbo].[sp_ReadErrorLog] @LogFilename [varchar](1000) = NULL AS SET NOCOUNT ON DECLARE @CMDStatement [varchar](8000) IF @LogFilename IS NULL BEGIN EXEC master.dbo.xp_regread 'HKEY_LOCAL_MACHINE', 'SOFTWARE\Microsoft\MSSQLServer\MSSQLServer\Parameters', 'SQLArg1', @param = @LogFilename OUTPUT SET @LogFilename = RIGHT(@LogFilename, LEN(@LogFilename) - 2) END
CREATE TABLE #LogFile ( [Line_id] [int] NOT NULL IDENTITY(1, 1), [LogText] [varchar](8000) ) SET @CMDStatement = 'TYPE "' + @LogFilename + '"' INSERT INTO #LogFile([LogText]) EXEC master.dbo.xp_cmdshell @CMDStatement SELECT * FROM #LogFile DROP TABLE #LogFile SET NOCOUNT OFF GO |