Search code examples
sql-servert-sqlsql-server-2000

How to catch the output of a DBCC-Statement in a temptable


I tried the following on SQL-Server:

create table #TmpLOGSPACE(
  DatabaseName varchar(100)
  , LOGSIZE_MB decimal(18, 9)
  , LOGSPACE_USED decimal(18, 9)
  ,  LOGSTATUS decimal(18, 9)) 

insert #TmpLOGSPACE(DatabaseName, LOGSIZE_MB, LOGSPACE_USED, LOGSTATUS) 
DBCC SQLPERF(LOGSPACE);

...but this rises an syntax-error...

Any sugestions?


Solution

  • Put the statement to be run inside EXEC('')

    insert #TmpLOGSPACE(DatabaseName, LOGSIZE_MB, LOGSPACE_USED, LOGSTATUS) 
    EXEC('DBCC SQLPERF(LOGSPACE);')