In these days, I needed to manipulate Query statement in Oracle. Because, for database part, we don't want our CF to calculate the amount of our system. That's why we just let Oracle to do as much as database part can do. Because we don't want JRun can be more loaded because of such calculation and minor cases and we are always try to assign less process for our CF. Today, I need to develop some calculation in our projects for the following cases.

view plain print about
1<cfif ONHAND_QTY + PROJECTED_QTY GT MIN_QTY>
2    <!--- ONHAND_QTY + PROJECTED_QTY ARE GREATER THAN MIN_QTY --->
3    <cfset IsReplenish = "Y">
4<cfelse>
5    <!--- ONHAND_QTY + PROJECTED_QTY ARE NOT GREATER THAN MIN_QTY --->
6    <cfset IsReplenish = "N">
7</cfif>

My senior wants me to do above calculation in database part. It's sweet challenge for me to make calculation in database part because I'm very new in Oracle and not have that much experience in Oracle. For this challenge, I think DECODE and CASE WHERE can solve for sure. Among these twos, I've selected DECODE as my boss.

Here is the usage and description for DECODE.

decode(expression , search , result [, search , result]... [, default])

Now, here is solution for my problem to calculate above transaction for database part..

view plain print about
1<CFQUERY name="getitemstore" datasource="myDSN">
2 SELECT DECODE(TRUNC((ONHAND_QTY + PROJECTED_QTY)/MIN_QTY), 0, 'Y', 1, 'N') REP
3 FROM TBL_TRX)QTY
4 ORDER BY ITEM_CODE
5</CFQUERY>