• Not that I want to say this script isn't great but...

    Why the hell would you load this into a text file, then parse the text file?

    When you could use the with TABLERESULTS option?

    declare @databaseName

    declare @DBCCCheckDBResults table

    (

    [DBCCCheckDBResultsID] [int] IDENTITY(1,1) NOT NULL,

    [ServerName] [varchar](255) NULL,

    [NodeName] [varchar](255) NULL,

    [DatabaseName] [varchar](255) NULL,

    [Error] [bigint] NULL,

    [Level] [bigint] NULL,

    [State] [bigint] NULL,

    [MessageText] [varchar](8000) NULL,

    [RepairLevel] [bigint] NULL,

    [Status] [bigint] NULL,

    [DbId] [bigint] NULL,

    [ObjectId] [bigint] NULL,

    [IndexId] [bigint] NULL,

    [PartitionId] [bigint] NULL,

    [AllocUnitId] [bigint] NULL,

    [File] [bigint] NULL,

    [Page] [bigint] NULL,

    [Slot] [bigint] NULL,

    [RefFile] [bigint] NULL,

    [RefPage] [bigint] NULL,

    [RefSlot] [bigint] NULL,

    [Allocation] [bigint] NULL,

    [RunDate] [datetime] NULL

    )

    insert @DBCCCheckDBResults

    (

    Error

    ,Level

    ,State

    ,MessageText

    ,RepairLevel

    ,Status

    ,DbId

    ,ObjectId

    ,IndexId

    ,PartitionId

    ,AllocUnitId

    ,[File]

    ,Page

    ,Slot

    ,RefFile

    ,RefPage

    ,RefSlot

    ,Allocation

    )

    exec (''dbcc checkdb (['' + @databaseName + '']) with TABLERESULTS'')


    Over 12yrs in IT and 10yrs happily stuck with SQL.
    - SQL 2008/R2/2012/2014/2016/2017
    - Oracle 8/9/10/11
    - MySQL 4/5 and MariaDB