--EXEC 输出变量值
DECLARE @RowCount int
DECLARE @sqlstr nvarchar(4000)
DECLARE @tableName nvarchar(100)
--表名,应用可能有更复杂的参数需要连接
SET @tableName='TEST'
SET @sqlstr='SELECT @iRowCount=COUNT(*) FROM '+ @tableName
EXEC sp_executesql @sqlstr,N'@iRowCount int output',@RowCount output
SELECT @RowCount
DECLARE @RowCount int
DECLARE @sqlstr nvarchar(4000)
DECLARE @tableName nvarchar(100)
--表名,应用可能有更复杂的参数需要连接
SET @tableName='TEST'
SET @sqlstr='SELECT @iRowCount=COUNT(*) FROM '+ @tableName
EXEC sp_executesql @sqlstr,N'@iRowCount int output',@RowCount output
SELECT @RowCount