DECLARE @T INT
EXEC('SELECT @T = count(user_id) FROM ( .. .. .. )')
PRINT @T
I guess the example is sufficient to explain what i am trying to do, i create dynamic query and want to access its count outside the exec statement.
I am using SQL 2000. How can this be achieved ?
You’d need to use sp_executesql which allows you to pass parameters in and out.
Main thing other than the solution below, is make sure you do really need dynamic SQL.
e.g.