The “trick” to making this work is to encapsulate the DBCC command as a string, and to call it with the EXECUTE () function. This is used as part of an INSERT INTO / EXECUTE statement, so that the results from DBCC PAGE are inserted into a table (in this case a temporary table is used, although a table variable or permanent table can also be used). There are three simple steps to this process:
Create a table (permanent / temporary) or table variable to hold the output.
Insert into this table the results of the DBCC PAGE statement by using INSERT INTO / EXECUTE.
Select the data that you are looking for from the table.
Read on for his code as well as important caveats.