title: Using the SQL syntax CASE returning unknown error message "THEN1"
body: <p>Hi can anyone help me with the below,  I have tried changing the DEC to INT which has no effect, my system is running a DERBY syntax which <code>CASE</code> is accepted so not sure why the below isn't working.</p>
  <p><strong>The error message being received is:</strong></p>
  <blockquote>
  <p>BIC00004. DAL01008. An error occurred while accessing the database.</p>
  <p>Syntax error: Encountered &quot;THEN1&quot; at line 1, column 416.&quot;</p>
  </blockquote>
  <p><strong>My query is as follows:</strong></p>
  <pre><code>SELECT
      G.&quot;GROUP&quot;
      , G.&quot;GROUP.DESC&quot;
      , G.SIZE
      , G.&quot;SIZE.DESC&quot;
      , G.&quot;WH.AREA&quot;
      , G.OSQTY AS &quot;SALES.RATIO.QTY&quot;
      , F.QTY AS &quot;MAX HOLDING&quot;
      , E.&quot;DUE OUT OSQTY&quot; AS  &quot;OUT THIS WEEK&quot;
      , D.&quot;OUT THIS WEEK OSQTY&quot;
      , C.&quot;DUE IN THIS WEEK OSQTY&quot;
      , B.&quot;CURRENT STOCK&quot; 
      , A.&quot;ACTUAL ORDERS&quot;
      , H.NAME
      , (CASE 
          WHEN CAST (G.&quot;WH.AREA&quot; AS DEC) = CAST (90 AS DEC) THEN CAST (SUM(G.OSQTY) AS DEC)
          WHEN CAST (G.&quot;WH.AREA&quot; AS DEC) = CAST (91 AS DEC) THEN CAST (SUM(G.OSQTY) AS DEC)
          WHEN CAST (G.&quot;WH.AREA&quot; AS DEC) = CAST (93 AS DEC) THEN CAST (SUM(G.OSQTY) AS DEC)
          WHEN CAST (G.&quot;WH.AREA&quot; AS DEC) = CAST (900 AS DEC) THEN CAST (SUM(G.OSQTY) AS DEC)
          WHEN CAST (G.&quot;WH.AREA&quot; AS DEC) = CAST (901 AS DEC) THEN CAST (SUM(G.OSQTY) AS DEC)
          WHEN CAST (G.&quot;WH.AREA&quot; AS DEC) = CAST (903 AS DEC) THEN CAST (SUM(G.OSQTY) AS DEC)
          WHEN CAST (G.&quot;WH.AREA&quot; AS DEC) = CAST (904 AS DEC) THEN CAST (SUM(G.OSQTY) AS DEC)
          ELSE CAST('99999999999'AS DEC) 
      END) AS &quot;salesratiosum&quot;
  FROM &quot;vol.sales.ratio&quot; G
      INNER JOIN &quot;vol.max.holding&quot; F
      ON (F.SIZE = G.SIZE AND F.&quot;PRODUCT.GROUP&quot; = G.&quot;GROUP&quot; AND F.WH = G.&quot;WH.AREA&quot;)
      LEFT JOIN &quot;vol.due.out.this.week&quot; E
      ON (F.WH = E.&quot;WH.AREA&quot; AND F.SIZE = E.SIZE AND F.&quot;PRODUCT.GROUP&quot; = E.&quot;GROUP&quot;)
      LEFT JOIN &quot;vol.due.out.next.week&quot; D
      ON (F.WH = D.&quot;WH.AREA&quot; AND F.SIZE = D.SIZE AND F.&quot;PRODUCT.GROUP&quot; = D.&quot;GROUP&quot;)
      LEFT JOIN &quot;vol.due.in.this.week&quot; C
      ON (F.WH = C.BRANCH AND F.SIZE = C. SIZE AND F.&quot;PRODUCT.GROUP&quot; = C.&quot;GROUP&quot;)
      INNER JOIN &quot;vol.current.stock.holding&quot; B
      ON (F.WH = B.WAREHOUSE AND F.SIZE = B.SIZE AND F.&quot;PRODUCT.GROUP&quot; = B.&quot;GROUP&quot;)
      LEFT JOIN &quot;vol.actual.orders&quot; A
      ON (F.WH = A.BRANCH AND F.SIZE = A.SIZE AND F.&quot;PRODUCT.GROUP&quot; = A.&quot;GROUP&quot;)
      INNER JOIN Warehouses H
      ON (F.WH = H.WAREHOUSE)
  GROUP BY 
      G.&quot;GROUP&quot;
      , G.&quot;GROUP.DESC&quot;
      , G.SIZE
      , G.&quot;SIZE.DESC&quot;
      , G.&quot;WH.AREA&quot;
      , G.OSQTY
      , F.QTY
      , E.&quot;DUE OUT OSQTY&quot;
      , D.&quot;OUT THIS WEEK OSQTY&quot;
      , C.&quot;DUE IN THIS WEEK OSQTY&quot;
      , B.&quot;CURRENT STOCK&quot;
      , A.&quot;ACTUAL ORDERS&quot;
      , H.NAME
  </code></pre>