DECLARE

       @TABLE_NAME sysname,

       @sql nvarchar(4000)

 

SET NOCOUNT ON

 

CREATE TABLE #temp

    (

    TABLE_QUALIFIER sysname,

    TABLE_OWNER sysname,

    TABLE_NAME sysname,

    TABLE_TYPE varchar(32),

    REMARKS varchar(254)

    )

 

INSERT INTO #temp

EXEC sp_tables 'tbl%' -- change to desired pattern

 

EXEC sp_executesql N'ALTER TABLE #temp ADD Processed bit NOT NULL DEFAULT (0)'

 

WHILE (SELECT COUNT(*) FROM #temp WHERE Processed = 0) > 0

BEGIN

       SET @TABLE_NAME = (SELECT TOP 1 TABLE_NAME FROM #temp WHERE Processed = 0)

       -- replace next line with your SQL statement

       SET @sql = 'SELECT COUNT(*) FROM ' + @TABLE_NAME

       EXEC sp_executesql @sql

       UPDATE #temp SET Processed = 1 WHERE TABLE_NAME = @TABLE_NAME

END

 

DROP TABLE #temp