MaxDB SAP SQL Missing keyword WITH on update - sql

Hi there I'm using MaxDB and trying to update a table and I get the error Missing keyword:WITH. Code: -5015.
Here is my SQL:
UPDATE agm
SET agm_confirm_stat = 'C',
agm_confirm_usr = 'MEDICWARE',
agm_confirm_obs = 'Wellon: Confirmado',
agm_obs = NVL(agm_obs, '') || '\/\/Wellon: Confirmar',
agm_confirm_dthr = TIMESTAMP
WHERE (agm_pac = '319900')
AND (
agm_obs NOT LIKE '%Wellon: Confirmar%'
OR agm_obs IS NULL
)
AND (agm_str_cod = 'FBC')
AND (agm_hini = '2022-12-07 08:00:00')
AND (agm_confirm_stat != 'C')
AND (agm_stat = 'A')

Related

SQL Update query with condition

Is it better that I just use the where for update query with conditions or there is a better way to do?
Below is a sample of my SQL query which I wanted to update if the Order_ID = 10 plus payment_check is N or response_msg is null, kindly correct me if my query is wrong.
UPDATE dbo.sample1
SET Payment_Generated = 'Y',
Transaction_ID = '123',
Response_Msg = 'ok',
Response_Code = '1',
Created_on = '2020-05-29T11:29:30'
WHERE Order_ID = '10' and Payment_Check = 'N' or Response_Code IS NULL
Expected Result if the payment_check is N or response_code is null
Payment_Generated = 'Y',
Transaction_ID = '123',
Response_Msg = 'ok',
Response_Code = '1',
Created_on = '2020-05-29T11:29:30'
Order_ID = '10'
Payment_Check = 'N'

nested clob xmlelemnt oracle sql select

I get this error when trying to run this sql scrip, I've searched alot for converting clob to varchar2 but useless
ORA-00932: inconsistent datatypes: expected - got CLOB
SELECT XMLELEMENT("ejada:PrivilegeResourcesList",XMLATTRIBUTES(NOENTITYESCAPING GET_MCR_PARAMETER('xmlns:core') AS "xmlns:core", GET_MCR_PARAMETER('xmlns:ejada') AS "xmlns:ejada"),
XMLAGG(XMLELEMENT("ejada:PrivilegeResourcesInfo",XMLELEMENT("ejada:PrivilegeRec",
XMLELEMENT("ejada:FuncId","F_CODE"),
XMLELEMENT("ejada:SCId","PS_CHANNEL_ID"),
XMLELEMENT("ejada:SrcResourcesList","SRCLIST"),
XMLELEMENT("ejada:TargResourcesList","TRGLIST"),
XMLELEMENT("ejada:Status","PS_STATUS")
)))) .GETCLOBVAL()
INTO P_PRIVILEGE_RESOURCES_LIST
from (
SELECT distinct
F_CODE, PS_CHANNEL_ID,
(
SELECT XMLAGG(XMLELEMENT ("core:ResourceInfo",XMLELEMENT ("core:ResourceId",
DECODE(PR_RESOURCE_TYPE_ID,
'1', XMLELEMENT("core:AcctId",XMLELEMENT("core:AcctId","PR_RESOURCE_VALUE")),
'2', XMLELEMENT("core:BillId",XMLELEMENT("core:BillNum","PR_RESOURCE_VALUE")),
'3', XMLELEMENT("core:BenId",XMLELEMENT("core:BenCode","PR_RESOURCE_VALUE"))
))
,XMLELEMENT("core:ResourceType","PRT_RESOUCE_TYPE_NAME_E")
)).GETCLOBVAL() FROM(SELECT PR_RESOURCE_TYPE_ID, PR_RESOURCE_VALUE, PRT_RESOUCE_TYPE_NAME_E FROM PERMISSION_RESOURCES, PERM_RESOURCE_TYPES WHERE PR_PERMISSION_ID = P.PS_PERMISSION_ID AND PR_USAGE_TYPE = 'S' AND PR_RESOURCE_TYPE_ID = PRT_RESOURCE_TYPE_ID)
) SRCLIST,
(
SELECT XMLAGG(XMLELEMENT ("core:ResourceInfo",XMLELEMENT ("core:ResourceId",
DECODE(PR_RESOURCE_TYPE_ID,
'1', XMLELEMENT("core:AcctId",XMLELEMENT("core:AcctId","PR_RESOURCE_VALUE")),
'2', XMLELEMENT("core:BillId",XMLELEMENT("core:BillNum","PR_RESOURCE_VALUE")),
'3', XMLELEMENT("core:BenId",XMLELEMENT("core:BenCode","PR_RESOURCE_VALUE"))
))
,XMLELEMENT("core:ResourceType","PRT_RESOUCE_TYPE_NAME_E")
)).GETCLOBVAL() FROM(SELECT PR_RESOURCE_TYPE_ID, PR_RESOURCE_VALUE, PRT_RESOUCE_TYPE_NAME_E FROM PERMISSION_RESOURCES, PERM_RESOURCE_TYPES WHERE PR_PERMISSION_ID = P.PS_PERMISSION_ID AND PR_USAGE_TYPE = 'D' AND PR_RESOURCE_TYPE_ID = PRT_RESOURCE_TYPE_ID)
) TRGLIST,
PS_STATUS
FROM FUNCTIONS F , SERVICES S , PERMISSIONS P
WHERE PS_STATUS = 'A'
--AND PS_COMP_TYPE_ID = v_component_type
-- AND Ps_COMPONENT_ID = v_component_id
AND PS_ROLE_ID = P_ROLE_ID
AND PS_ROLE_ID IN (SELECT R_ROLE_ID
FROM ROLES
WHERE R_ROLE_ID=P_ROLE_ID AND
R_COMP_TYPE_ID = 'ORGZ' AND
R_COMPONENT_ID= P_ORG_ID)
AND PS_FUNCTION_ID = F_code
AND F_SERVICE_ID = S_SERVICE_ID
-- AND PS_PERMISSION_ID = PR_PERMISSION_ID
ORDER BY F_CODE
) ;

Error "ORA-00936: missing expression" for below SQL statement

Please help to check why below SQL statement got error of "ORA-00936: missing expression" when executed on Oracle 11g R2.
select part.*,
decode(pv.dspuom, null, part.untqty, part.untqty / prtftp_dtl.untqty) dsp_untqty,
decode(pv.dspuom, null, pv.stkuom, pv.dspuom) untqty_uom,
decode(pv.dspuom, null, cast(null as int), pv.stkuom, cast(null as int), mod(part.untqty, prtftp_dtl.untqty)) rem_untqty,
decode(pv.dspuom, null, null, pv.stkuom, null, pv.stkuom) rem_untqty_uom
from (select #select_on:raw sum(untqty) untqty,
sum(catch_qty) catch_qty,
invadj.prtnum fixed_prtnum,
invadj.prt_client_id fixed_prt_client_id,
invadj.wh_id fixed_wh_id,
invadj.play_prc_id
from invadj
where exists(select 'x'
from prtmst_view
where prtmst_view.prtnum = invadj.prtnum
and prtmst_view.prt_client_id = invadj.prt_client_id
and prtmst_view.wh_id = invadj.wh_id
and prtmst_view.prdflg = 1)
and #+moddte:date
and #+invadj.play_prc_id
and #+invadj.prtnum
and #+invadj.prt_client_id
and wh_id = #wh_id
and #*
group by #result_string:raw,
invadj.prtnum,
invadj.prt_client_id,
invadj.wh_id,
invadj.play_prc_id
having sum(untqty) <> 0
or sum(catch_qty) <> 0) part left
join prtmst_view pv
on pv.prtnum = part.fixed_prtnum
and pv.prt_client_id = part.fixed_prt_client_id
and pv.wh_id = part.fixed_wh_id left
join prtftp
on prtftp.prtnum = pv.prtnum
and prtftp.prt_client_id = pv.prt_client_id
and prtftp.wh_id = pv.wh_id
and prtftp.defftp_flg = 1 left
join prtftp_dtl
on prtftp.prtnum = prtftp_dtl.prtnum
and prtftp.ftpcod = prtftp_dtl.ftpcod
and prtftp.prt_client_id = prtftp_dtl.prt_client_id
and prtftp.wh_id = prtftp_dtl.wh_id
and prtftp_dtl.uomcod = nvl(pv.dspuom, pv.stkuom)
I think the syntax may be off a bit.
Look at this line below
FROM (SELECT # select_on:raw sum(untqty) untqty,
The # character seems odd

Run the query nd found the ERROR

I am trying this query but found the error on &CLEARED_FLAG
ORA-00933: SQL command not properly ended
SELECT vch_locn_code
,vch_vch_type
,vch_vch_#
,vch_srl_#
,vch_bank_code
,vch_instrmt_type
,vch_instrmt_num
,vch_instrmt_date
,vch_instrmt_amt
,vch_drawn_at
,vch_payable_at
,vch_dshnr_flag
,vch_rcln_flag
,vch_rcln_date
,vch_trns_type
,vch_payee_name
,vch_bv_date
,vch_clear_date
,dd_no
,dd_dt
,cleared_dt
FROM fac_vch_bv
WHERE vch_bv_date BETWEEN :from_date AND :to_date
AND vch_locn_code = :locn_code
AND vch_vch_# IN (SELECT DISTINCT vch_vch_#
FROM fac_vch_d
WHERE vch_gl_code = :bank_code
AND vch_dbcr = (SELECT decode(:bank_receipt, 'Y', 'D', 'N', 'C') FROM dual)
AND vch_vch_type = '0102')
AND vch_vch_# IN (SELECT vch_vch_#
FROM fac_vch_m
WHERE vch_vch_type = '0102'
AND vch_bank_code = :bank_code) &cleared_flag
ORDER BY vch_instrmt_num
,vch_instrmt_date

How to join three tables?

SELECT
PC_SL_ACNO, -- DB ITEM
SLNAME, -- ACCOUNT NAME:
SL_TOTAL_AMOUNT -- TOTAL AMOUNT:
FROM GLAS_PDC_CHEQUES
WHERE PC_COMP_CODE=:parameter.COMP_CODE
AND pc_bank_from = :block02.pb_bank_code
AND pc_due_date between :block01.date_from
AND :block01.date_to
AND nvl(pc_discd,'X') IN(‘X’, 'R')
GROUP BY
pc_comp_code, pc_sl_ldgr_code, pc_sl_acno
ORDER BY pc_sl_acno
ACCOUNT NAME:
BEGIN
SELECT COAD_PTY_FULL_NAME INTO :BLOCK03.SLNAME
FROM GLAS_PTY_ADDRESS,GLAS_SBLGR_MASTERS
WHERE SLMA_COMP_CODE = :PARAMETER.COMP_CODE
AND SLMA_ADDR_ID = COAD_ADDR_ID
AND SLMA_ADDR_TYPE = COAD_ADDR_TYPE
AND SLMA_ACNO = :BLOCK03.PC_SL_ACNO
AND SLMA_COMP_CODE = COAD_COMP_CODE;
EXCEPTION WHEN OTHERS THEN NULL;
END;
TOTAL AMOUNT:
BEGIN
SELECT SUM(PC_AMOUNT) INTO :SL_TOTAL_AMOUNT
FROM GLAS_PDC_CHEQUES
WHERE PC_DUE_DATE BETWEEN :BLOCK01.DATE_FROM AND :BLOCK01.DATE_TO
AND PC_BANK_FROM = :block02.PB_BANK_CODE
AND PC_SL_ACNO = :BLOCK03.PC_SL_ACNO
AND NVL(PC_DISCD,'X') = 'R'
AND PC_COMP_CODE = :PARAMETER.COMP_CODE;
EXCEPTION WHEN OTHERS THEN :block03.SL_TOTAL_AMOUNT := 0;
END;
How can I join the three tables?
You'll have to adjust depending on precisely what criteria and required fields you have for your query or queries.
SELECT
c.PC_SL_ACNO,
a.COAD_PTY_FULL_NAME,
SUM(c.PC_AMOUNT)
FROM
GLAS_PDC_CHEQUES c
LEFT JOIN
GLAS_SBLGR_MASTERS m
ON ( c.PC_SL_ACNO = m.SLMA_ACNO
AND c.PC_COMP_CODE = m.SLMA_COMP_CODE
)
LEFT JOIN
GLAS_PTY_ADDRESS a
ON ( m.SLMA_ADDR_ID = a.COAD_ADDR_ID
AND m.SLMA_COMP_CODE = a.COAD_COMP_CODE
AND m.SLMA_ADDR_TYPE = a.COAD_ADDR_TYPE
)
WHERE
c.PC_COMP_CODE = :PARAMETER.COMP_CODE
AND c.PC_SL_ACNO = :BLOCK03.PC_SL_ACNO
AND c.PC_BANK_FROM = :BLOCK02.PB_BANK_CODE
AND NVL(c.PC_DISCD,'X') IN (‘X’, 'R')
AND c.PC_DUE_DATE BETWEEN :BLOCK01.DATE_FROM AND :BLOCK01.DATE_TO
GROUP BY
c.PC_SL_ACNO, -- not sure which grouping exactly you need.
a.COAD_PTY_FULL_NAME
ORDER BY
c.PC_SL_ACNO
I notice that in the first query you have pc_comp_code as a search criterion, and on the leading edge of your grouping - is that what you need?
This is a bit of an 'estimate' due to the enigmatic nature of your question!