If you must do it this way you would have to use sp_executeSql,Brief exampleDECLARE @sql NVARCHAR(4000)DECLARE @outputVariable INT -- Change to required datatypeSET @sql = 'SELECT @output = Employee where EmployeeCode=1'EXEC sp_executeSql @sql, N'@output INT OUTPUT', @outputVariable OUTPUT
However, as you are not making up your query (it's getting returned from proc?)You'd have to do something like< You declerations -- I am assuming you are assigning the output of your stored proc to a variable called @sql which is of type NVARCHAR - this is important)>DECLARE @outputVariable INT -- Change this to the datatype that you are afterSET @sql = REPLACE(@sql, 'SELECT', 'SELECT @output = ')EXEC sp_executeSql @sql, N'@output INT OUTPUT', @outputVariable OUTPUT
-------------Charlie