Saturday, January 19, 2008

Oracle 10g: Create If-else within SQL Query

/*
How to create if-else when you have a comparison on a field in a certain query...? I Cut off all those if-else massive code and use 'case' in the sql statement...
*/

SELECT mstorganization.orgname, mstorganization.orgdocno,

mstorganization.orgshortform, mstorganization.website,
mstorganization.email,
CASE WHEN reforg.typedescription = '' THEN ' - '
ELSE reforg.typedescription
END AS "DOCTYPE", reforgtype.typedescription orgtypedesc,
mstorganization.ORGTYPE
FROM gbl_organization_mst mstorganization, gbl_refcode reforg,
gbl_refcode reforgtype
WHERE ( (mstorganization.orgid = ORGID_)
AND (mstorganization.branchid = BRANCHID_)
AND (mstorganization.orgdoctype = reforg.typeid(+))
AND (mstorganization.ORGTYPE = reforgtype.typeid(+))
);

2 comments:

Anonymous said...

You made my day! :-)

peah @ peps said...

hehe..glad to make you happy today..