What is the best way to do the equivalent of execute scalar in T-SQL? In other words, using SQL, how can I get the first column of the first row of the first result set when I call a stored procedure?
Edit: Just to clarify, this is only using SQL, no client-side language. The result set could be something like:
Id Description
--------------
1 foo
2 bar
I only want "1" in a variable.
The only way I know how to do this is with a temp table (untested, but you get the idea):
INSERT #TempTable EXEC MyStoredProcedure
DECLARE @id INT;
SELECT TOP(1) @id = Id FROM #TempTable