Steps to insert error log records into temporary table


You can follow the below steps to enter error log records into temporary table and query it.

-- Command will create the temporary table in tempdb
CREATE TABLE [dbo].[#TmpErrorLog]
([LogDate] DATETIME NULL,
 [ProcessInfo] VARCHAR(20) NULL,
 [Text] VARCHAR(MAX) NULL ) ;

-- Command will insert the errorlog data into temporary table
INSERT INTO #TmpErrorLog ([LogDate], [ProcessInfo], [Text])
EXEC [master].[dbo].[xp_readerrorlog] 0 ;

-- retrieves the data from temporary table
SELECT * FROM #TmpErrorLog
Advertisements

2 thoughts on “Steps to insert error log records into temporary table

  1. Abhinav Andhare

    Jugal, looks Awesome and we can use this on the mission critical situations to dig more from error logs…
    I like to add here

    run the xp_enumerrorlogs stored procedure and get the number of file numbers and insert all the data to the temp table to be more priciese…

    Thanks again for uploading this article…

    Good Learning this

    Abhinav

    Reply
  2. capgemini

    You can use this too…

    Begin
    /*declaring sql variable */
    declare
    @sql varchar(1000)
    set
    @sql=”
    /* Creating a temp table */
    create
    table #errors
    (
    rowid
    int identity,
    entrytime
    datetime,
    source
    varchar(50),
    logentry
    varchar(4000)
    )
    /* assigning errorlog to @sql variable */
    select
    @sql= ‘EXEC master..xp_readerrorlog’
    /* inserting errorlog from variable into table */
    insert
    into #errors (entrytime,source,logentry)
    execute
    (@sql)
    select
    * from #errors
    –drop table #errors
    end

    Reply

Thanks for the comment, will get back to you soon... Jugal Shah

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s