Solved

Sybase Stored Procedure Creation Doubt

Posted on 2012-03-26
3
662 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 13

Expert Comment

by:alpmoon
ID: 37768980
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
ID: 37769243
@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
ID: 37769549
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
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…

733 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