SQL Convert Page Nums

Convert Page Nums

-- Convert page numbers in sysindexes to decimal form for use 
-- with DBCC commands


CREATE PROC ConvertPageNums
as
/* You can modify this procedure to accept a table name and/or index
   name as parameters, and then only return the corresponding rows 
   from sysindexes. 
   This procedure is provided 'as-is'
*/

select 	convert(char(30), name) 'name', 
	id, 
	indid, 
	convert(varchar(2), (convert(int, substring(first, 6, 1)) * power(2, 8)) + (convert(int, substring(first, 5, 1)))) + ':' +
	convert(varchar(11), 
	(convert(int, substring(first, 4, 1)) * power(2, 24)) + 
	(convert(int, substring(first, 3, 1)) * power(2, 16)) + 
	(convert(int, substring(first, 2, 1)) * power(2, 8)) + 
	(convert(int, substring(first, 1, 1)))) 'first',
	first,
	convert(varchar(2), (convert(int, substring(root, 6, 1)) * power(2, 8)) + (convert(int, substring(root, 5, 1)))) + ':' +
	convert(varchar(11), 
	(convert(int, substring(root, 4, 1)) * power(2, 24)) + 
	(convert(int, substring(root, 3, 1)) * power(2, 16)) + 
	(convert(int, substring(root, 2, 1)) * power(2, 8)) + 
	(convert(int, substring(root, 1, 1)))) 'root',
	root,
	convert(varchar(2), (convert(int, substring(firstIAM, 6, 1)) * power(2, 8)) + (convert(int, substring(FirstIAM, 5, 1)))) + ':' +
	convert(varchar(11), 
	(convert(int, substring(firstIAM, 4, 1)) * power(2, 24)) + 
	(convert(int, substring(firstIAM, 3, 1)) * power(2, 16)) + 
	(convert(int, substring(firstIAM, 2, 1)) * power(2, 8)) + 
	(convert(int, substring(firstIAM, 1, 1)))) 'firstIAM',
	firstIAM
from sysindexes