Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Conditional replace statement

Status
Not open for further replies.

JonathanHolliday

Technical User
Aug 20, 2003
9
GB
Hi,

I'm looking for a simple statement to conditionally replace a value.

I have a value field that could be negative or positive depending on a Debit/Credit field.

Thus I need to query something like:

select {IF type = "debit" THEN value ELSE value * -1}
from table

Obviously the code in {} doesn't exist, is there such a code in informix without resorting to a procedure?

Yes, I'm new to Informix so forgive the fundamental question.

Thanks

Jonathan.
 
Hi,

You may use the sql keyword DECODE to accomplish this.

create temp table tab1 (type char(6), value dec(10,2)) with no log;
insert into tab1 values ('credit',-1000.00);
insert into tab1 values ('credit',-2000.00);
insert into tab1 values ('debit ',500.00);
insert into tab1 values ('debit ',800.00);

select type,value,decode(type,"debit",value,value*-1) from tab1;

Regards,
Shriyan

"An ounce of example is worth a pound of advice."
 
Shriyan,

Thank you, that's perfect. You're right about eg.s as well.

Regards,

Jonathan.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top