>>USE AP >> >>DECLARE @DynamicSQL VARCHAR(max) >>DECLARE @TableNameVar sysname >>SELECT @TableNameVar = MIN(name) from sys.tables -- here we don't need dynamic SQL, we need to get the name of the table >>SET @DynamicSQL = >> 'SELECT COUNT(*) AS [Countof' +@TableNameVar + '] FROM ' + quotename(@TableNameVar) >>--print (@DynamicSQL) -- we may want to use PRINT to debug the SQL >>EXEC (@DynamicSQL) >>>>>