T-SQL get SELECTed value of stored procedure
Posted
by David
on Stack Overflow
See other posts from Stack Overflow
or by David
Published on 2010-05-21T09:44:59Z
Indexed on
2010/05/21
9:50 UTC
Read the original article
Hit count: 185
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!)
© Stack Overflow or respective owner