• SQL parses your script and finds that you are attempting to create it in two different places, and so raises an error, its better to create the table in the beginning with common columns and add the specific columns in the if--else based on the condition

    Declare @Version int;

    select @version=(SUBSTRING(CONVERT(VARCHAR(50),SERVERPROPERTY('productversion')), 1,2))

    IF OBJECT_ID('tempdb..#checkresults') IS NOT NULL

    DROP TABLE #checkresults

    create table #checkresults

    (

    [Error] [int] NULL,

    [Level] [int] NULL,

    [State] [int] NULL,

    [MessageText] [varchar](650) NULL,

    [RepairLevel] [varchar](150) NULL,

    [Status] [int] NULL,

    [DbId] [int] NULL,

    --[DbFragId] [int] NULL,

    [ObjectId] [int] NULL,

    [IndexId] [int] NULL,

    [PartitionId] [int] NULL,

    [AllocUnitId] [int] NULL,

    --[RidDbId] [int] NULL,

    --[RidPruId] [int] NULL,

    [File] [int] NULL,

    [Page] [int] NULL,

    [Slot] [int] NULL,

    --[RefDbId] [int] NULL,

    --[RefPruId] [int] NULL,

    [RefFile] [int] NULL,

    [RefPage] [int] NULL,

    [RefSlot] [int] NULL,

    [Allocation] [int] NULL )

    if (@version >=11)

    begin

    alter table #checkresults add

    [DbFragId] [int] NULL,

    [RidDbId] [int] NULL,

    [RidPruId] [int] NULL,

    [RefDbId] [int] NULL,

    [RefPruId] [int] NULL

    end

    drop table #checkresults