title: Why is my query failing with SQLCODE=-204?
body: <p>I'm writing some SQL for a report (this is my first time actually writing SQL so don't slam my syntax too much, lol) and the subquery seems to be failing. I'm not sure why because the report compiles just fine and I can get it into Jaspersoft Studio before it errors out when trying to preview it. Am I even doing the subquery correctly?</p>
  
  <p>Thanks in advance.</p>
  
  <pre><code>SELECT
      PERSON.LAST_NAME,
      ACCOUNT.ACCOUNT_NUMBER, 
      SHARE_ESCROW.ID,
      LOAN.PAYMENT_DUE_DATE, 
      LN_IMPOUND_ANALYSIS.CUSHION_AMOUNT, 
      LN_IMPOUND_ANALYSIS.NEXT_P_AND_I_AMOUNT,
      LOAN.IMPOUND_AMOUNT,
      LN_IMPOUND_ANALYSIS.NEXT_IMPOUND_AMOUNT,
      SHARE_ESCROW.BALANCE, 
      SHARE_ESCROW.DESCRIPTION, 
      SHARE_ESCROW.CLOSE_DATE,
      i.LTV,
      CASE LOAN.PAYMENT_METHOD
          WHEN 'T' THEN 'Automated Transfer'
          WHEN 'A' THEN 'ACH'
          WHEN 'C' THEN 'Cash'
      END AS PAYMENT_METHOD
  FROM    
      CORE.ACCOUNT AS ACCOUNT INNER JOIN CORE.LOAN AS LOAN ON ACCOUNT.SERIAL = LOAN.PARENT_SERIAL INNER JOIN
      CORE.LN_IMPOUND_ANALYSIS AS LN_IMPOUND_ANALYSIS ON LOAN.SERIAL = LN_IMPOUND_ANALYSIS.PARENT_SERIAL INNER JOIN
      CORE.SHARE AS SHARE_ESCROW ON ACCOUNT.SERIAL = SHARE_ESCROW.PARENT_SERIAL INNER JOIN
      CORE.PERSON AS PERSON ON PERSON.SERIAL = ACCOUNT.PRIMARY_PERSON_SERIAL,
      (SELECT 
          CASE COLLATERAL.AMOUNT
              WHEN 0 THEN 0
              WHEN NULL THEN 0
              ELSE LOAN.BALANCE / COLLATERAL.AMOUNT
          END AS LTV
  
      FROM
          CORE.COLLATERAL AS COLLATERAL INNER JOIN LOAN ON LOAN.SERIAL = COLLATERAL.PARENT_SERIAL
      ) i
  WHERE
      SHARE_ESCROW.DESCRIPTION = 'Escrow Share' AND 
      SHARE_ESCROW.CLOSE_DATE IS NULL AND
      i.LTV != 0
  </code></pre>
  
  <p>Edit: 
  Here's the error:</p>
  
  <pre><code>net.sf.jasperreports.engine.JRException: net.sf.jasperreports.engine.JRRuntimeException: net.sf.jasperreports.engine.JRException: Error executing SQL statement for : Escrow32Analysis324532WIP_TableDataset_1579697577915_289752
      at com.jaspersoft.studio.editor.preview.view.control.ReportControler.fillReport(ReportControler.java:466)
      at com.jaspersoft.studio.editor.preview.view.control.ReportControler.access$18(ReportControler.java:441)
      at com.jaspersoft.studio.editor.preview.view.control.ReportControler$4.run(ReportControler.java:333)
      at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)
  Caused by: net.sf.jasperreports.engine.JRRuntimeException: net.sf.jasperreports.engine.JRException: Error executing SQL statement for : Escrow32Analysis324532WIP_TableDataset_1579697577915_289752
      at net.sf.jasperreports.engine.fill.JRFillSubreport.prepare(JRFillSubreport.java:809)
      at net.sf.jasperreports.components.table.fill.FillTableSubreport.prepareSubreport(FillTableSubreport.java:156)
      at net.sf.jasperreports.components.table.fill.FillTable.prepare(FillTable.java:400)
      at net.sf.jasperreports.engine.fill.JRFillComponentElement.prepare(JRFillComponentElement.java:151)
      at net.sf.jasperreports.engine.fill.JRFillElementContainer.prepareElements(JRFillElementContainer.java:332)
      at net.sf.jasperreports.engine.fill.JRFillBand.fill(JRFillBand.java:384)
      at net.sf.jasperreports.engine.fill.JRFillBand.fill(JRFillBand.java:358)
      at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillSummaryNoLastFooterSamePage(JRVerticalFiller.java:1102)
      at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillSummary(JRVerticalFiller.java:1065)
      at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportEnd(JRVerticalFiller.java:329)
      at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:159)
      at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:963)
      at net.sf.jasperreports.engine.fill.BaseFillHandle$ReportFiller.run(BaseFillHandle.java:120)
      at java.lang.Thread.run(Unknown Source)
  Caused by: net.sf.jasperreports.engine.JRException: Error executing SQL statement for : Escrow32Analysis324532WIP_TableDataset_1579697577915_289752
      at net.sf.jasperreports.engine.query.JRJdbcQueryExecuter.createDatasource(JRJdbcQueryExecuter.java:240)
      at net.sf.jasperreports.engine.fill.JRFillDataset.createQueryDatasource(JRFillDataset.java:1114)
      at net.sf.jasperreports.engine.fill.JRFillDataset.initDatasource(JRFillDataset.java:691)
      at net.sf.jasperreports.engine.fill.JRBaseFiller.setParameters(JRBaseFiller.java:1314)
      at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:931)
      at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:873)
      at net.sf.jasperreports.engine.fill.JRFillSubreport.fillSubreport(JRFillSubreport.java:665)
      at net.sf.jasperreports.engine.fill.JRSubreportRunnable.run(JRSubreportRunnable.java:59)
      at net.sf.jasperreports.engine.fill.AbstractThreadSubreportRunner.run(AbstractThreadSubreportRunner.java:203)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
      ... 1 more
  Caused by: com.ibm.db2.jcc.am.SqlSyntaxErrorException: DB2 SQL Error: SQLCODE=-204, SQLSTATE=42704, SQLERRMC=CMURPHY.LOAN, DRIVER=4.13.127
      at com.ibm.db2.jcc.am.id.a(id.java:677)
      at com.ibm.db2.jcc.am.id.a(id.java:60)
      at com.ibm.db2.jcc.am.id.a(id.java:127)
      at com.ibm.db2.jcc.am.no.c(no.java:2653)
      at com.ibm.db2.jcc.am.no.d(no.java:2641)
      at com.ibm.db2.jcc.am.no.a(no.java:2090)
      at com.ibm.db2.jcc.am.oo.a(oo.java:7671)
      at com.ibm.db2.jcc.t4.cb.h(cb.java:141)
      at com.ibm.db2.jcc.t4.cb.b(cb.java:41)
      at com.ibm.db2.jcc.t4.q.a(q.java:32)
      at com.ibm.db2.jcc.t4.sb.i(sb.java:135)
      at com.ibm.db2.jcc.am.no.ib(no.java:2059)
      at com.ibm.db2.jcc.am.oo.sc(oo.java:3559)
      at com.ibm.db2.jcc.am.oo.b(oo.java:4348)
      at com.ibm.db2.jcc.am.oo.fc(oo.java:743)
      at com.ibm.db2.jcc.am.oo.executeQuery(oo.java:713)
      at net.sf.jasperreports.engine.query.JRJdbcQueryExecuter.createDatasource(JRJdbcQueryExecuter.java:233)
      ... 11 more
  </code></pre>