Solved

Sybase Stored Procedure Creation Doubt

Posted on 2012-03-26
3
668 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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

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.
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
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…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

729 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