Yuri55 (5/26/2013)
Here we are (sorry, if this is wrong way to post script):
******************************************************************
USE [DBA]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- ============================================================
--rebuild index using dbo.index_rebuild_log ahead prepared data
-- ============================================================
CREATE PROCEDURE [dbo].[usp_IndexRebuild]
AS
BEGIN
SET NOCOUNT ON;
declare @start datetime
declare @id int, @dbname varchar(50), @tblname varchar(100), @indexname varchar(100), @schname varchar(20), @action char(10)
declare @sql nvarchar(1000) = ''
DECLARE curDB CURSOR FORWARD_ONLY STATIC FOR
SELECT id, dbname, schname, tblname, indexname, [action]
FROM dbo.index_rebuild_log --ahead prepared fragmentation data
WHERE index_done = 0
ORDER BY id
OPEN curDB
FETCH NEXT FROM curDB INTO @id, @dbname, @schname, @tblname, @indexname, @action
WHILE @@FETCH_STATUS = 0
BEGIN
set @start = GETDATE()
set @sql = 'ALTER INDEX ' + @indexname + ' ON ' + @dbname + '.' + @schname + '.' + @tblname + ' ' + @action
--print @sql
exec sp_executesql @sql
update dbo.index_rebuild_log --report action completion
set
index_done = 1,
index_start = @start,
index_end = GETDATE()
where
id = @id
FETCH NEXT FROM curDB INTO @id, @dbname, @schname, @tblname, @indexname, @action
END
CLOSE curDB
DEALLOCATE curDB
END -- << Is there anything after this END?
Is there anything following the last END statement when you script the stored procedure using Object Explorer?