SELECT * FROM DBCC xxx | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

SELECT * FROM DBCC xxx

Hi, Is there any possibility to use the output of DBCC xxxx commands as a subquery? Because I didn’t achieve it. My goal is to insert certain columns in a temporary table. For example
SELECT A.ObjectName, A.ScanDensity FROM
(dbcc showcontig (t_testtable) with tableresults, all_indexes) A I tried to execute this T-SQL Statement with different syntax (exec .. etc), but I didn’t achieve it and am getting some errors like the following. Server: Nachr.-Nr. 156, Schweregrad 15, Status 1, Zeile 3
Incorrect syntax near the keyword ‘dbcc’.
Server: Nachr.-Nr. 170, Schweregrad 15, Status 1, Zeile 3
Line 3: Incorrect syntax near ‘)’. Thanks in advance for your help.
Try INSERT INTO #temptable
EXEC (‘DBCC SHOWCONTIG (‘t_testtable’) WITH TABLERESULTS, ALL_INDEXES, NO_INFOMSGS’)

Excellent suggestion from Thomas – if you duplicate the single quotes in the actual command: INSERT INTO #temptable
EXEC (‘DBCC SHOWCONTIG (”t_testtable”) WITH TABLERESULTS, ALL_INDEXES, NO_INFOMSGS’)

Hi Thomas, first of all, thanks for your suggestion. It would function, if I create temptable with all its columns. It’s acceptable.
But is there any possibility to use for a subquery the output of the dbcc command.
No .. it’s all the columns or nothing.
If it is a fuction it will have the option what you are looking like in sql 2005… Check the BOL topic "DBCC SHOWCONTIG" for script to populate the table with DBCC SHOWCONTIG output and DEXDEFRAG them… MohammedU.
Moderator
SQL-Server-Performance.com
]]>