Solved

Sybase Stored procedue doubt

Posted on 2012-04-05
2
754 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article describes some very basic things about SQL Server filegroups.
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
The viewer will learn how to implement Singleton Design Pattern in Java.
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…

863 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

28 Experts available now in Live!

Get 1:1 Help Now