Solved

Sybase Stored Procedure Creation Doubt

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Fixing Non-Standard characters in text 8 111
Slow SQL query 12 61
SQL Query 34 115
T-SQL: Do I need CLUSTERED here? 13 59
I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
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…

808 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