Need to send computed value in stored procedure parameter

I want to call stored procedure, passing parameter values while computing.

EXEC Procedure_Name @Parameter1-1, @Parameter2

I don’t want to use any other variable.

  • 1

    You can’t carry out any form of computation, calculation, function call as part of calling the SP. Nada

    – 

  • It is not possible without using variable

    – 

You could just do the addition in a statement before going into the stored procedure resuing parameter 1

set @Parameter1= @Parameter1+1;
EXEC Procedure_Name @Parameter1, @Parameter2

You can achieve it using dynamic SQL to avoid variable for calculation. Something like below should work for you.

DECLARE @Script     NVARCHAR(1000)
DECLARE @Parameter1 INT
DECLARE @Parameter2 INT

SET @Parameter1 = 10
SET @Parameter2 = 10

SET @Script = N'EXEC Procedure_Name @Param1 = ' + CAST(@Parameter1 - 1 AS NVARCHAR(10)) + ', @Param2 = @Parameter2'

PRINT @Script
EXEC (@Script)

But its not recommended to use dynamic SQL for such simple purpose.

Leave a Comment