Solved

Sybase Stored Procedure Creation Doubt

Posted on 2012-03-26
3
628 Views
Last Modified: 2012-04-02
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...
0
Comment
Question by:gaugeta
  • 2
3 Comments
 
LVL 13

Expert Comment

by:alpmoon
Comment Utility
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"
0
 

Author Comment

by:gaugeta
Comment Utility
@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.
0
 
LVL 13

Accepted Solution

by:
alpmoon earned 500 total points
Comment Utility
I don't think that there is any other way of doing it other than embedding it in the stored procedure logic. You are looking for a syntax like 'case' for parameters, it is not available as it is designed only for the case parameter doesn't have a value.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

I guess that all of us know that caching the data usually increase the performance, but I worried if all of us are aware about the risk that caching the data provides and how to minimize this.  That’s the reason why I decided to write this short art…
Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now