T-SQL get SELECTed value of stored procedure
- by David
In T-SQL, this is allowed:
DECLARE @SelectedValue int
SELECT @SelectedValue = MyIntField FROM MyTable WHERE MyPrimaryKeyField = 1
So, it's possible to get the value of a SELECT and stuff it in a variable (provided it's scalar, obviously).
If I put the same select logic in a stored procedure:
CREATE PROCEDURE GetMyInt
AS
SELECT MyIntField FROM MyTable WHERE MyPrimaryKeyField = 1
Can I get the output of this stored procedure and stuff it in a variable?
Something like:
DECLARE @SelectedValue int
SELECT @SelectedValue = EXEC GetMyInt
(I know the syntax above is not allowed because I tried it!)