Why can I not use functions to directly assign stored procedure parameters?
e.g.
exec myStoredProc @firstParam = aFunctionThatReturnsAnAppropriateValue()
but I find I have to decalre a variable just to hold the value
declare @temp type = aFunctionThatReturnsAnAppropriateValue()
exec myStoredProc @firstParam = @temp
which seems redundant
Quoting EXECUTE (Transact-SQL):
You can see that it explicitly says
@variableorvalue. I guess this is a language limitation, as you can neither write a call to a function as a variable or as a value; it is executable code (an expression), and the short-hand assignment during variable declaration is just a misleading bonus.EDIT: Compare the difference of description for
DECLAREandEXECUTE:For
DECLAREWhen looking through the page for
EXECUTE, I do not see the mention of an expression. It seems to me that it would be handy, as I think you are trying to point out.