Hi there,
I am writing a cursor which counts the number of records for a particular table. The cursor gets the table name from a metatable. At the moment the cursor just prints the sql statement but doesn't execute it, can someone help with the syntax.
thanks
DECLARE @tablename AS VARCHAR(50)
DECLARE Record_Count CURSOR FOR
SELECT TABLENAME
FROM METATABLE
WHERE TABLETYPE = 1
OPEN Record_Count
FETCH NEXT FROM Record_Count
INTO @tablename
WHILE @@FETCH_STATUS = 0
BEGIN
select ''+@tablename+', count(*) from '+@tablename+''
FETCH NEXT FROM Record_Count
INTO @tablename
END
CLOSE Record_Count
DEALLOCATE Record_Count
GO
I am writing a cursor which counts the number of records for a particular table. The cursor gets the table name from a metatable. At the moment the cursor just prints the sql statement but doesn't execute it, can someone help with the syntax.
thanks
DECLARE @tablename AS VARCHAR(50)
DECLARE Record_Count CURSOR FOR
SELECT TABLENAME
FROM METATABLE
WHERE TABLETYPE = 1
OPEN Record_Count
FETCH NEXT FROM Record_Count
INTO @tablename
WHILE @@FETCH_STATUS = 0
BEGIN
select ''+@tablename+', count(*) from '+@tablename+''
FETCH NEXT FROM Record_Count
INTO @tablename
END
CLOSE Record_Count
DEALLOCATE Record_Count
GO