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 statement in SQL string

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-08-02, 07:51
Maurizio Maurizio is offline
Registered User
 
Join Date: Aug 2002
Location: italy
Posts: 5
IF statement in SQL string

I need to use an IF statement in a SQL string but i don't know if it's possible.

i use an alias to select a value of C, this field is always
greater then 0 but i want to transform it in negative or positive value depending the value of D...


select A, B.....

if D='55' then C else -C as E...

from... etc.. etc...

Is it possible insert IF statment in a select statement?
How is the correct syntax?

tanks...
Reply With Quote
  #2 (permalink)  
Old 11-10-02, 21:47
rnealejr rnealejr is offline
Registered User
 
Join Date: Feb 2002
Posts: 2,232
Try the following:

select field1, field2, case when d="55" then "result 1"
else "result2" end field3
from table;
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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