8

Above the call to this stored procedure is another call to a different stored procedure. The first procedure will assign something to @NewIdentifier if it needs to, otherwise I need to use the default SaleId.

exec myStoredProc @SaleId = ISNULL(@NewIdentifier, @SaleId)

It works if I do it this way

declare @Id int
set @Id = ISNULL(@NewIdentifier, @SaleId)
exec myStoredProc @SaleId = @Id

Is it possible to use ISNULL in the assignment of a stored procedure parameter? I'm not sure what is invalid about this syntax.

Brandon
  • 68,708
  • 30
  • 194
  • 223

2 Answers2

9

The parameter must be a constant or a variable. It cannot be an expression.

Joe Stefanelli
  • 132,803
  • 19
  • 237
  • 235
0

Is it possible that the '=' operator has lower precedence than '(' ? If so, it would be parsed as exec myStoredProc (@SaleId = ISNULL) (@NewIdentifier, @SaleId), which would be a syntax error.