title: can't define condition
body: <p>im trying to define the condition <code>SR.PRODUCT_STOCK2 &gt; 0</code> inside the sql code, since it <code>AS</code> of sum condition, here is the sql code</p>
  
  <pre><code>    SELECT P.PRODUCT_ID,P.PRODUCT_NAME,PS.MONEY,PR.PRICE,P.BRAND_ID,PS.PRICE,GSL.PRODUCT_STOCK,GSL.PURCHASE_ORDER_STOCK,GSL.SALEABLE_STOCK,P.PRODUCT_DETAIL2,P.BARCOD
  &lt;cfif isdefined('attributes.department_id') and len(attributes.department_id)&gt;
      ,(SUM(SR.STOCK_IN)-SUM(SR.STOCK_OUT)) AS PRODUCT_STOCK2
  &lt;/cfif&gt;
  FROM PRODUCT P
      JOIN PRICE_STANDART PS ON P.PRODUCT_ID = PS.PRODUCT_ID
      JOIN PRICE PR ON P.PRODUCT_ID = PR.PRODUCT_ID
      JOIN #DSN2_ALIAS#.GET_STOCK_LAST GSL ON P.PRODUCT_ID = GSL.PRODUCT_ID
      &lt;cfif isdefined('attributes.department_id') and len(attributes.department_id)&gt;
          JOIN #DSN2_ALIAS#.STOCKS_ROW SR ON P.PRODUCT_ID=SR.PRODUCT_ID
      &lt;/cfif&gt;
  WHERE PS.PURCHASESALES=1 AND PS.PRICESTANDART_STATUS=1 AND P.IS_SALES=1 AND P.IS_PURCHASE=1 AND P.IS_INTERNET=1 AND P.IS_EXTRANET=1
  &lt;cfif isdefined('attributes.department_id') and len(attributes.department_id)&gt;
      AND
          (
          &lt;cfloop list="#attributes.department_id#" delimiters="," index="dept_i"&gt;
          (SR.STORE = #listfirst(dept_i,'-')# AND SR.STORE_LOCATION = #listlast(dept_i,'-')#)
          &lt;cfif dept_i neq listlast(attributes.department_id,',') and listlen(attributes.department_id,',') gte 1&gt; OR&lt;/cfif&gt;
          &lt;/cfloop&gt;  
          )
          &lt;cfif isdefined('attributes.is_stock') and attributes.is_stock is 1&gt;
              AND SR.PRODUCT_STOCK2 &gt; 0
          &lt;/cfif&gt;
      &lt;/cfif&gt;
  GROUP BY P.PRODUCT_ID,PR.PRICE,P.PRODUCT_NAME,PS.MONEY,P.BRAND_ID,PS.PRICE,GSL.PRODUCT_STOCK,GSL.PURCHASE_ORDER_STOCK,GSL.SALEABLE_STOCK,P.PRODUCT_DETAIL2,P.BARCOD
  </code></pre>
  
  <p>the error log says: Invalid column name <code>PRODUCT_STOCK2</code> i know that i wrongly defined the condition, i just don't know how to define it right, need help! Thanks everyone for help!</p>