title: CASE Clause on select clause throwing 'SQLCODE=-811, SQLSTATE=21000' Error
body: <p>This query is very well working in Oracle. But it is not working in DB2. It is throwing </p>
  
  <blockquote>
    <p>DB2 SQL Error: SQLCODE=-811, SQLSTATE=21000, SQLERRMC=null, DRIVER=3.61.65</p>
  </blockquote>
  
  <p>error when the sub query under <code>THEN</code> clause is returning 2 rows. </p>
  
  <p>However, my question is why would it execute in the first place as my WHEN clause turns to be false always.</p>
  
  <pre><code>SELECT 
  CASE
  WHEN (SELECT COUNT(1)
    FROM STOP ST,
      FACILITY FAC
    WHERE ST.FACILITY_ID     = FAC.FACILITY_ID
    AND FAC.IS_DOCK_SCHED_FAC=1
    AND ST.SHIPMENT_ID       = 2779) = 1
  THEN
    (SELECT ST.FACILITY_ALIAS_ID
    FROM STOP ST,
      FACILITY FAC
    WHERE ST.FACILITY_ID     = FAC.FACILITY_ID
    AND FAC.IS_DOCK_SCHED_FAC=1
    AND ST.SHIPMENT_ID       = 2779
    )
  ELSE NULL
  END STAPPFAC
  FROM SHIPMENT SHIPMENT
  WHERE SHIPMENT.SHIPMENT_ID IN (2779);
  </code></pre>