Subquery SQL DB2

0

I am trying to make a subquery (in a particular column) within the base query. The code is as follows.

select
z.po_id,
max(SELECT etcdc.ship_evnt_tms from COVINFOS.SHIPMENT_EVENT etcdc where 
etcdc.SHIP_EVNT_CD = '9P' and etcdc.ship_id=scdc.ship_id
order by etcdc.updt_job_tms, desc fetch first row only) as 
LLP_estimated_delivery_cdc
from covinfos.ibm_plant_order z
left join COVINFOS.IPO_LINE_TO_CASE A ON z.po_id = a.po_id
left JOIN COVINFOS.SHIPMENT scdc ON (A.SHIP_ID = scdc.SHIP_ID AND 
A.SHIP_TO_LOC_CODE = scdc.SHIP_TO_LOC_CODE and scdc.loc_type = 'CDC')
group by z.po_id

It seems that there is some kind of syntax error based on the error message that comes out when I try to run the query.

BIC00004. DAL01008. An error occurred while accessing the database.
ILLEGAL SYMBOL ".". SOME SYMBOLS THAT MIGHT BE LEGAL ARE: , ). SQLCODE=-104, 
SQLSTATE=42601, DRIVER=3.62.56; THE CURSOR SQL_CURLH200C1 IS NOT IN A 
PREPARED STATE. SQLCODE=-514, SQLSTATE=26501, DRIVER=3.62.56

However, at first glance or at least, my view, there is no error. Also, running the subselect separately, if it runs.

Thanks

    
asked by Juan Ignacio Durante 17.04.2018 в 21:48
source

1 answer

0

You have one more comma in the fifth line

order by etcdc.updt_job_tms, desc fetch first row only) as 

Change it to

order by etcdc.updt_job_tms desc fetch first row only) as 
    
answered by 17.04.2018 в 22:01