Hello!! I am using SQL Server 2008 and I am attempting to create a stored procedure to Truncate certain tables in my database so that I can rewrite records to those tables on a nightly basis from Access tables. The problem I am having is that my fetch always returns only the first record from my table (AccessCopyTables). Can someone please tell me what I am doing wrong? Here is the sproc:
Thanks for the help in advance!!Code:USE [Mercury] GO /****** Object: StoredProcedure [dbo].[TruncTables] Script Date: 04/12/2010 14:52:30 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER PROCEDURE [dbo].[TruncTables] AS DECLARE @TName nchar(30) DECLARE @query nvarchar(max) DECLARE @curs cursor SET @curs = CURSOR FOR SELECT TableName FROM AccessCopyTables OPEN @curs FETCH NEXT FROM @curs INTO @TName WHILE @@FETCH_STATUS = 0 BEGIN PRINT 'Table Name ' + @TName set @query = N'TRUNCATE TABLE ' + @TName exec sp_executesql @query END FETCH NEXT FROM @curs INTO @TName END CLOSE @curs DEALLOCATE @curs




Reply With Quote