Link to home
Start Free TrialLog in
Avatar of GAUTAM
GAUTAMFlag for United States of America

asked on

Sybase Stored Procedure Creation Doubt

I have a general doubt regarding creating stored procedues which can substitue different values say null when 0 or 0.0 is passed as an argument. Right now i know to create a stored procedure which can use the default value only if nothing is passed to the parameter.

create proc myproc
          ( @myparam1  int = 0,
            @myparam2  float ,
            @myparam3  char(20) = "mydefault")

.... Here if i pass a 0 to the first parameter which is of an int type and if i pass 0.0 to the second parameter i want to substitute as null. But i dont want to do the same inside the main logic of the stored procedure. How can i achieve the same...
Please help...
Avatar of alpmoon
alpmoon
Flag of Australia image

If I don't misunderstand what you want, you can only do it in the stored procedure by assigning null value:

if @myparam1 = 0
    select @myparam1 = null

Maybe you should explain what you mean with "inside the main logic of the stored procedure"
Avatar of GAUTAM

ASKER

@alpmoon:Thanks for the reply.
Just like we have the default values for the parameteres which get added if nothing is passed to the parameter,i was wondering if there was a method to specify an alternate value to a specific  parameter in the parameter definition stsge itself instead of embedding in the stored rocedure logic using if else.
ASKER CERTIFIED SOLUTION
Avatar of alpmoon
alpmoon
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial