Home > Blockchain >  Is there a way to set default stored procedure parameter values with a calculation based on another
Is there a way to set default stored procedure parameter values with a calculation based on another

Time:08-26

I'm making a stored procedure with three parameters: @type, @range_min, @range_max.

  • @range_min should be, by default, equal to @type - 10000.
  • @range_max should be, by default, equal to @type 10000.

Is it possible to set these defaults in the declaration section of the stored procedure?

Something like this:

CREATE PROCEDURE SP_TEST
    (@type int = 100000,
     @range_min int = @tipo_mantencion - 10000,
     @range_max int = @tipo_mantencion   10000)
AS
BEGIN

If this is not possible, is the best choice to use an IF to check if it's null and then set it to the default value I need?

Thanks! (I'm using SQL Server)

CodePudding user response:

Not possible and defaulting to null and conditionally setting the value is the usual practice.

  • Related