Hello. I'm am trying to write a cursor in SQL Server 2000 that looks in a table with a list of tablenames (UpdateTables), looks up the number of rows in that table and then enters the number of rows in the second column of the lookup table against the correct tablename. I have written the following but am getting an error message saying that I need to declare the variable @tblName
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[sp_UpdateTablesUpdate]
as
DECLARE CrExtractUpdateCount CURSOR FOR SELECT Tablename FROM dbo.UpdateTables
DECLARE @tblName char(50)
OPEN CrExtractUpdateCount
FETCH NEXT FROM CrExtractUpdateCount
INTO @tblName
WHILE @@FETCH_STATUS = 0
BEGIN
UPDATE UpdateTables
SET Number_Rows = (select count (*) from @tblName)
WHERE dbo.[UpdateTables].[Tablename] = @tblName
FETCH NEXT FROM CrExtractUpdateCount
INTO @tblName
END
CLOSE CrExtractUpdateCount
DEALLOCATE CrExtractUpdateCount
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
any help much appreciated.