If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Informix > If construct

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-03-09, 11:37
Ato Ato is offline
Registered User
 
Join Date: Feb 2009
Posts: 3
If construct

Hi, in the following mysql select statement i use an if construct to get a sign changed in the recordset.

SELECT a.fieldone, a.fieldtwo, if(a.fieldone="x",a.fieldthree,-a.fieldthree) as myfield FROM mytable a

I would like to have the same result on an informix db. Is it possible? If so, what is the If syntax?

Many thanks in advance.

//andrea
Reply With Quote
  #2 (permalink)  
Old 07-03-09, 13:58
bigcalm bigcalm is offline
Registered User
 
Join Date: Jul 2009
Posts: 37
decode() is functionally similar.

Manual and examples here - IBM Informix Dynamic Server v10 Information Center

SELECT a.fieldone, a.fieldtwo, decode(a.fieldone,"x",a.fieldthree,-a.fieldthree) as myfield
FROM mytable a
Reply With Quote
  #3 (permalink)  
Old 07-05-09, 05:02
Ato Ato is offline
Registered User
 
Join Date: Feb 2009
Posts: 3
thanks a lot, bigcalm
Reply With Quote
  #4 (permalink)  
Old 07-06-09, 18:33
Tyveleyn Tyveleyn is offline
Registered User
 
Join Date: Aug 2006
Location: The Netherlands
Posts: 248
Or CASE. Is more useful then decode() when an unknown kind of different cases have to be covered by ELSE.
Code:
SELECT  CASE fieldone
	WHEN 'x' THEN fieldthree
	WHEN 'y' THEN ...
	ELSE -fieldthree
	END myfield
FROM mytable;
Regards,
Hans
Reply With Quote
  #5 (permalink)  
Old 07-27-09, 03:25
sunbo sunbo is offline
Registered User
 
Join Date: Jul 2009
Posts: 1
Dear players, do you need Gold for WOW? We provide you withWOW Gold, cheap WOW Gold, including
World of Warcraft EU Gold aWorld of Warcraft US Gold . Also we supply Metin2 Yang and Metin2 Gold to Metin2 players. Besides we also offer WOW Level Power Leveling.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On