Solved

Sybase Stored procedue doubt

Posted on 2012-04-05
2
816 Views
Last Modified: 2012-08-13
Hi Experts...
I have around say 50 variables in a sybase stored procedure whose value is calculated within the stored procedure by a mathematical procedure.
I have a condition such that if the value of the 50 variables is  lesser than 10 then the value should be made as 0.
I could do as follows:
if @val1 < 10
         select  @val1=0
if @val2 < 10
         select @val2=0 ...........and so on till 50 values.

Is there a way in sybase to change all these values to 0 if the values of the variables  are less than 10 or keep them as it is if they have a value greater than 10.
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 Comments
 
LVL 14

Accepted Solution

by:
Jan_Franek earned 500 total points
ID: 37812433
AFAIK there is no such way.

You may create subprocedure with 1 parameter to check and modify one value:

create procedure my_sub_procedure ( @val int output )
as
if @val < 10
  select @val = 0
go

and then replace all your if's in main procedure:

exec my_sub_procedure @val1 output
exec my_sub_procedure @val2 output
etc.

This is not much better than original. But if you decide to move your limit from 10 to 20,  you just have to change one short subprocedure.

Just to be sure - do you really need procedure ? SQL is set oriented and is much more effective when dealing with whole table, than dealing with one row at a time.
0
 
LVL 24

Expert Comment

by:Joe Woodhouse
ID: 37843274
I'd put the 50 variables into a temp table, one row per variable, then run a single update to apply your logic.
0

Featured Post

Industry Leaders: 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

Suggested Solutions

In this post we will learn different types of Android Layout and some basics of an Android App.
This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

732 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