informix equalivalent for 'decode'statement in oracle

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
Pavan_Yelugula
Premium Member
Premium Member
Posts: 133
Joined: Tue Nov 23, 2004 11:24 pm
Location: India

informix equalivalent for 'decode'statement in oracle

Post by Pavan_Yelugula »

hi all

we have this requirement where if a countrycode(parameter) is specified we should get the data from the table where the countrycode column in the table matches the parameter value. if nothing is specified all the data for all the countries should be retrieved

we found this out and rote a query in my ODBC stage accordingly

select * from COMET_TEST.REFERENCETABLE where SRC_CNTRY_CD =(DECODE('#CountryCode#','',SRC_CNTRY_CD,'#CountryCode#') )

This works great i am able to achieve my objective.
but some of my tables are in informix and the same function is not working can anyone tell me the equavalent for this in informix

any inputs will be really helpful
Thanks and regards
Pavan
Sainath.Srinivasan
Participant
Posts: 3337
Joined: Mon Jan 17, 2005 4:49 am
Location: United Kingdom

Post by Sainath.Srinivasan »

I believe version 7.3 onwards of Informix Dynamic Server provides Decode function.

You can check it and its syntax on 'Informix Online'.
Pavan_Yelugula
Premium Member
Premium Member
Posts: 133
Joined: Tue Nov 23, 2004 11:24 pm
Location: India

Post by Pavan_Yelugula »

i m using 7.1 can you please tell me if there is any round about way of getting the functionality
Sainath.Srinivasan
Participant
Posts: 3337
Joined: Mon Jan 17, 2005 4:49 am
Location: United Kingdom

Post by Sainath.Srinivasan »

Use an OR clause as below

Select *
From Country
Where ('#CountryParameter#' = '')
Or (ContryCode = '#CountryParameter#')
Pavan_Yelugula
Premium Member
Premium Member
Posts: 133
Joined: Tue Nov 23, 2004 11:24 pm
Location: India

Post by Pavan_Yelugula »

Thanks a lot it was a good idea

it is working great
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

DECODE can have more than two options.

Most databases' SQL has a CASE construct that you can use if there is no DECODE available.

Code: Select all

SELECT CASE WHEN '#CountryParameter#' = '' THEN SRC_CNTRY_CD
            WHEN '#CountryParameter#' IS NULL THEN SRC_CNTRY_CD
            ELSE '#CountryParameter#' 
       END AS CNTRY_CODE
FROM #SchemaName#.REFERENCETABLE ;
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply