Get DBCC results in a table with other columns as well

  • I have a DBCC Statement, for which i get results into the table.

    Like this;

    Create table #getlogspace

    (

    dbname varchar(100) null,

    [logsize(MB)] varchar(10) null,

    [LogSpaceUser(%)] varchar(10) null,

    status int

    )

    --insert DBCC values into this Table

    insert into #getlogspace

    EXEC ('DBCC SQLPERF(LOGSPACE)')

    ---------- This Above Works Fine.----------------

    -----------Real Trouble Starts here--------------

    But when create the above table with additional Columns :

    Create table #getlogspace

    (

    infodate datetime null ,

    servername nvarchar(50) null ,

    dbname varchar(100) null,

    [logsize(MB)] varchar(10) null,

    [LogSpaceUser(%)] varchar(10) null,

    status int

    )

    I am unable to execute the above insert statement with Tweaks.

    What i do for now is Create Table without the infodate,servername columns and do the plain insert, then add column to the table and i do an update on the column to fill the values for the 2 clumns.

    I want to insert the value in all columns in ONE GO....

    Pl Help.

  • if the destination table has the eXACT same structure as the SELECt/DBCC, you do not need to mention the columns...since you added some extra fields, you have to explicitlu name the columns for the insert:

    insert into #getlogspace([dbname],[logsize(MB)],[LogSpaceUser(%)],[status])

    EXEC ('DBCC SQLPERF(LOGSPACE)')

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Exactly, here is what i did.

    I defined DEFAULT for the columns(infodate and servername) and then applied the insert.

    GREAT, thanks and ton.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply