To Get the value back to a variable you should use sp_ExecuteSQL
Here is an example of what I tried against AdventureWorks
DECLARE @SQL nvarchar(2000), @Rows int
SET @SQL =N'SELECT @RowCount =COUNT(*) FROM '+ +'Sales.SalesOrderHeader'
EXEC sp_ExecuteSQL @SQL, N'@RowCount int OUTPUT',@RowCount=@Rows OUTPUT
SELECT @Rows
I purposefully used @RowCount and @Rows to differentiate them. Hope this helps
G.R.Preethiviraj Kulasingham
|