Executing S.P. so default parameter values are used

  • I have a S.P. written like this

    create proc my_sp

    @p1 varchar (20) = 'Default',

    @p2 varchar (20),

    @p3 varchar (20)

    as

    --some code goes here...

    go

    My question is how do I execute this proc so the default value in parameter 1 (@p1) is used?

  • Don't call the parameter when you exec the SP

    exec my_sp

    @p2 = [some value]

    , @p3 = [some value]

    go

    _____________________________________________________________________
    - Nate

    @nate_hughes
  • Thanks RP

  • You could also use the DEFAULT reserved word in SQL this will force it to use the default value as well

    ----------------------------------------------
    Try to learn something about everything and everything about something. - Thomas Henry Huxley

    :w00t:
    Posting Best Practices[/url]
    Numbers / Tally Tables[/url]

    SQL-4-Life
  • I generally (ok -- always) put parameters with default values at the end of the list:

    create proc my_sp

    @p1 varchar (20),

    @p2 varchar (20),

    @p3 varchar (20) = 'Default'

    as

    --some code goes here...

    go

    That way I don't have to use parameter naming or the "default" keyword:

    exec my_sp @p1, @p2, @p3; -- provide a value

    exec my_sp @p1, @p2; -- use default for @p3It constantly irks me that this method is not allowed in functions.

    Tomm Carr
    --
    Version Normal Form -- http://groups.google.com/group/vrdbms

Viewing 5 posts - 1 through 4 (of 4 total)

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