none
CANT we set default value Null to parameter in stored procedure

    Question

  •  

    Hello

     

    I've written a stored procedure with 4 parameters

     

    create procedure dummy

    ( @a int, @b int, @c varchar(50), @d varchar(50))

     

    now from front end(I'm using c#.net)

    I want to send the values according to some criteria

    So in the process...I've only values for @a & @c ...

     

    so In order to reduce the code of sending Null values explicitly to other parameters...

     

    can't I set like default values for it so that If I don't send values to certain parameters it will have the default value or Null value.

     

    like I want something like this:

     

    create procedure dummy

    ( @a int NULL, @b int NULL, @c varchar(50) NULL, @d varchar(50) NULL)

     

    Monday, February 18, 2008 2:06 PM

Answers

  • You can.

     

    create procedure dummy

    ( @a int = NULL,

      @b int = NULL,

      @c varchar(50) = NULL,

      @d varchar(50) = NULL)

     

    This sets all parameters to default as NULL.

    It also makes it possible to execute the proc without providing any parameters.

     

    /Kenneth

     

    Monday, February 18, 2008 3:05 PM
    Moderator