Technical Article

Script to return Rows count from table using sp_ExecuteSQL

,

Script Example

DECLARE @TableNameVARCHAR(100)
DECLARE @varSQLNVARCHAR(4000)
DECLARE @iCountINT

SET@TableName = 'TimeZones'
SET@varSQL = 'SELECT TOP 1 @iCountOut = rows FROM sys.partitions where object_id = ' + CAST(object_id(@TableName) AS VARCHAR(100))

EXECUTE sp_ExecuteSQL @varSQL, N'@iCountOut INT OUTPUT', @iCountOut = @iCount OUTPUT
SELECT@iCount

Rate

2 (1)

You rated this post out of 5. Change rating

Share

Share

Rate

2 (1)

You rated this post out of 5. Change rating