Optional parameters

  • When writing a stored procedure, can I use optional input parameters, similar to optional arguments in functions?

    How to?

    Sam

  • Sure, just apply a default to the parameter

     

    Create procedure myprocedure @var1 int, @var2 int = 0

    as

    if @var2 <> 0

    begin

       Do something

    end

    Else

    Begin

       Do something else.

    End

    For this procedure to execute you Must supply a value for @Var1, but you are not required to pass a value for @var2

     

  • really cool!!!

    thanks

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply