This is just one of those little reminders to self. Self, you never seem to remember how to assign the return value from a stored procedure to a variable in SQL. I try various forms and always seem to miss the right one. So, in an effort to mark it for my future use, I place it here in the blog.
One does NOT accomplish it through any of these methods:
DECLARE @ReturnedValue INT
SET @ReturnedValue = StoredProcedure @Param1, @Param2
IF( @ReturnedValue = @Something )
--Do This Stuff
SET @ReturnedValue = StoredProcedure ( @Param1, @Param2 )
SET @ReturnedValue = EXEC StoredProcedure @Param1, @Param2
SET @ReturnedValue = EXEC StoredProcedure ( @Param1, @Param2 )
One does by this method:
EXEC @ReturnedValue = StoredProcedure @Param1, @Param2
I just have to remember the order. I suppose it makes sense when I see it, but I forget when it's time to type it. It's just too easy to get mixed up with Function format.