if exists (select * from sysobjects where id = object_id('dbo.usp_frag_report') and sysstat & 0xf = 4) drop procedure dbo.usp_frag_report GO create procedure usp_frag_report @login_name varchar(30) = NULL, @pwd varchar(30) = NULL, @target decimal(5,2) = 85.00, @file varchar(255) = 'c:\temp', @rebuild_ind char(1) = 'N' as begin declare @dbname varchar(30) set nocount on declare iw_dbcursor cursor for select name from master.dbo.sysdatabases where name not in ('master', 'model', 'pubs', 'tempdb', 'distribution', 'msdb') order by dbid open iw_dbcursor fetch next from iw_dbcursor into @dbname while @@fetch_status = 0 begin exec sp_get_dnsty @login_name, @pwd, @dbname, @target, @file, @rebuild_ind fetch next from iw_dbcursor into @dbname end close iw_dbcursor deallocate iw_dbcursor end GO