Related
I am trying to write a BQ Merge Query which does something like an upsert. I have a main table(M) and an identical delta table(D) which brings changed records. The merge statement should work like if the keys match it will update all the table fields in the main table with the delta table data and if the keys don't match it will do an insert of the delta table values. I was able to get the Merge statement to work but it seems too long. Is there a shorter way to do this . I have more than 190 columns in my table. Please see the Merge code below.
merge zsac_figl01.zsaplikp02 M
using zsac_figl01.zsaplikp02_delta D
on M.VBELN = D.VBELN
WHEN MATCHED THEN
UPDATE
SET
M.VBELN = D.VBELN ,
M.ERNAM = D.ERNAM ,
M.ERZET = D.ERZET ,
M.ERDAT = D.ERDAT ,
M.BZIRK = D.BZIRK ,
M.VSTEL = D.VSTEL ,
M.VKORG = D.VKORG ,
M.LFART = D.LFART ,
M.AUTLF = D.AUTLF ,
M.KZAZU = D.KZAZU ,
M.WADAT = D.WADAT ,
M.LDDAT = D.LDDAT ,
M.TDDAT = D.TDDAT ,
M.LFDAT = D.LFDAT ,
M.KODAT = D.KODAT ,
M.ABLAD = D.ABLAD ,
M.INCO1 = D.INCO1 ,
M.INCO2 = D.INCO2 ,
M.EXPKZ = D.EXPKZ ,
M.ROUTE = D.ROUTE ,
M.FAKSK = D.FAKSK ,
M.LIFSK = D.LIFSK ,
M.VBTYP = D.VBTYP ,
M.KNFAK = D.KNFAK ,
M.TPQUA = D.TPQUA ,
M.TPGRP = D.TPGRP ,
M.LPRIO = D.LPRIO ,
M.VSBED = D.VSBED ,
M.KUNNR = D.KUNNR ,
M.KUNAG = D.KUNAG ,
M.KDGRP = D.KDGRP ,
M.STZKL = D.STZKL ,
M.STZZU = D.STZZU ,
M.BTGEW = D.BTGEW ,
M.NTGEW = D.NTGEW ,
M.GEWEI = D.GEWEI ,
M.VOLUM = D.VOLUM ,
M.VOLEH = D.VOLEH ,
M.ANZPK = D.ANZPK ,
M.BEROT = D.BEROT ,
M.LFUHR = D.LFUHR ,
M.GRULG = D.GRULG ,
M.LSTEL = D.LSTEL ,
M.TRAGR = D.TRAGR ,
M.FKARV = D.FKARV ,
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T_SYSTEM,
D.SPE_INV_BFR_GI,
D.SPE_QI_STATUS,
D.SPE_RED_IND,
D.SAKES,
D.SPE_LIFEX_TYPE,
D.SPE_TTYPE,
D.SPE_PRO_NUMBER,
D.LOC_GUID,
D.SPE_BILLING_IND,
D.PRINTER_PROFILE,
D.MSR_ACTIVE,
D.PRTNR,
D.STGE_LOC_CHANGE,
D.TM_CTRL_KEY,
D.DLV_SPLIT_INITIA,
D.DLV_VERSION,
D.BEV1_LULEINH,
D.BEV1_RPFAESS,
D.BEV1_RPKIST,
D.BEV1_RPCONT,
D.BEV1_RPSONST,
D.BEV1_RPFLGNR,
D.BORGR_GRP,
D.ZLAND1,
D.ZZTVGW,
D.ZZVTW,
D.ZZFRGEW,
D.ZZANZPAL,
D.ZZKDKG1,
D.ZZVOLLPAL
)`
if the keys match it will update all the table fields in the main table with the delta table data and if the keys don't match it will do an insert of the delta table values
Based on above I assume the schema of main and delta table are identical
So, you can explore option of doing DELETE and INSERT instead of UPDATE and INSERT
Something like
DELETE zsac_figl01.zsaplikp02
WHERE VBELN IN (SELECT VBELN FROM zsac_figl01.zsaplikp02_delta)
And then (note - Omitting column names is in Beta since June 3, 2019, so you should try )
INSERT zsac_figl01.zsaplikp02
SELECT * FROM zsac_figl01.zsaplikp02_delta
I am just getting back into writing SQL Select Statements and I am have an issue. I have an existing report that works perfectly. However, I was asked to add some fields in the result set. The filed is in a table with a foreign key relationship. I am trying to add it to the query and I am failing. I can write the select statement separately and it returns the right results. I just don't know how to add it to the existing statement. I have tried left joins, adding it to the select and where but the result set is wrong. I would like to add the following to return the info if available to the result set in a new column but not prevent other data if null.
I would like to add:
select sc.FACILITY_ID, ce.schd_id
from PA_SCHED sc, PA_CPNT_EVTHST ce
where sc.SCHD_ID = ce.schd_id
To the following:
select s.stud_id as studID, s.lname as lastName, s.fname as firstName, s.mi
as middleName,
s.EMP_STAT_ID ,s.EMP_TYP_ID ,s.JL_ID ,s.JP_ID ,s.TARGET_JP_ID ,
s.JOB_TITLE ,s.DMN_ID ,s.ORG_ID ,s.REGION_ID, s.CO_ID , DECODE
(s.NOTACTIVE,'Y','N','N','Y') as active ,
s.ADDR ,s.CITY ,s.STATE ,s.POSTAL ,s.CNTRY, s.SUPER , s.COACH_STUD_ID ,
s.HIRE_DTE,s.TERM_DTE ,s.EMAIL_ADDR, s.RESUME_LOCN ,s.COMMENTS ,
s.SHIPPING_NAME ,
s.SHIPPING_CONTACT_NAME,
s.SHIPPING_ADDR ,s.SHIPPING_ADDR1 ,s.SHIPPING_CITY ,
s.SHIPPING_STATE,
s.SHIPPING_POSTAL ,s.SHIPPING_CNTRY ,s.SHIPPING_PHON_NUM,
s.SHIPPING_FAX_NUM,
s.SHIPPING_EMAIL_ADDR ,s.STUD_PSWD ,s.PIN ,s.PIN_DATE,
s.ENCRYPTED , s.HAS_ACCESS ,s.BILLING_NAME , s.BILLING_CONTACT_NAME ,
s.BILLING_ADDR ,s.BILLING_ADDR1 ,s.BILLING_CITY ,s.BILLING_STATE ,
s.BILLING_POSTAL,
s.BILLING_CNTRY ,
s.BILLING_PHON_NUM ,s.BILLING_FAX_NUM ,s.BILLING_EMAIL_ADDR ,
s.SELF_REGISTRATION ,s.SELF_REGISTRATION_DATE, s.ACCESS_TO_ORG_FIN_ACT ,
s.NOTIFY_DEV_PLAN_ITEM_ADD , s.NOTIFY_DEV_PLAN_ITEM_MOD ,
s.NOTIFY_DEV_PLAN_ITEM_REMOVE ,
s.NOTIFY_WHEN_SUB_ITEM_COMPLETE ,s.NOTIFY_WHEN_SUB_ITEM_FAILURE ,
s.LOCKED ,s.PASSWORD_EXP_DATE,s.SECURITY_QUESTION ,
s.SECURITY_ANSWER ,s.ROLE_ID ,s.IMAGE_ID ,s.GENDER ,s.PAST_SERVICE,
s.LST_UNLOCK_TSTMP,
s.LST_UPD_USR, s.LST_UPD_TSTMP,s.MANAGE_SUB_SP, s.MANAGE_OWN_SP,
e.cpnt_typ_id as cpntTypeID, e.cpnt_id as cpntID, e.rev_dte as revDate,
e.rev_num as revNum,
e.schd_id as schedID, cp.cpnt_title as cpntDesc, e.grade,
e.compl_dte as complDate, e.cmpl_stat_id as complStatID,
cs.cmpl_stat_desc as complStatDesc, nvl(e.total_hrs, 0) as totalHrs,
nvl(e.credit_hrs, 0) as creditHrs, nvl(e.contact_hrs, 0) as contactHrs,
nvl(e.cpe_hrs, 0) as cpeHrs, nvl(oi.price, 0) as tuition,
e.inst_name as instName, e.comments as eventComments, e.es_user_name as
esUserName,
e.lst_upd_tstmp as lstTmsp,
e.esig_meaning_code_id || ' ' || e.esig_meaning_code_desc as
esigMeaningCode,
e.currency_code as currencyCode, cur.symbol as currencySymbol,
cur.description,
cur.active, cur.is_default, cur.label_id
,s.jl_id
,s.job_title
,s.super
,s.hire_dte
,s.term_dte
,eeno.user_value
,co.user_value
from pa_student s, PA_CPNT_EVTHST e, PA_CMPL_STAT cs,
pa_fin_order_item oi, pa_currency cur, pa_cpnt cp,
(SELECT s.stud_id, f.user_value
FROM PA_STUD_USER f, pa_student s
WHERE s.stud_id = f.stud_id (+)
AND f.col_num (+) = '10') eeno
,(SELECT s.stud_id, f.user_value
FROM PA_STUD_USER f, pa_student s
WHERE s.stud_id = f.stud_id (+)
AND f.col_num (+) = '40') co
where e.stud_id = s.stud_id
and e.cmpl_stat_id = cs.cmpl_stat_id
and e.currency_code = cur.currency_code(+)
and e.order_item_id = oi.order_item_id(+)
and cp.cpnt_typ_id(+) = e.cpnt_typ_id
and cp.cpnt_id(+) = e.cpnt_id
and cp.rev_dte(+) = e.rev_dte
and s.stud_id = eeno.stud_id(+)
AND s.stud_id = co.stud_id(+)
/** and trunc(e.compl_dte) >= [FromDate]
and not trunc(e.compl_dte) > [ToDate]
and s.stud_id in [UserSearch]
and e.cpnt_typ_id in [ItemTypeSearch]
and [security:pa_student s] */
Thank you for your help.
Added this in FROM ...
(select sc.FACILITY_ID, ce.schd_id from PA_SCHED sc
where sc.SCHD_ID (+) = e.schd_id
) sc
and appended sc.FACILITY_ID in the main SELECT ...
See if this works ...
SELECT s.stud_id AS studID,
s.lname AS lastName,
s.fname AS firstName,
s.mi AS middleName,
s.EMP_STAT_ID ,
s.EMP_TYP_ID ,
s.JL_ID ,
s.JP_ID ,
s.TARGET_JP_ID ,
s.JOB_TITLE ,
s.DMN_ID ,
s.ORG_ID ,
s.REGION_ID,
s.CO_ID ,
DECODE (s.NOTACTIVE,'Y','N','N','Y') AS active ,
s.ADDR ,
s.CITY ,
s.STATE ,
s.POSTAL ,
s.CNTRY,
s.SUPER ,
s.COACH_STUD_ID ,
s.HIRE_DTE,
s.TERM_DTE ,
s.EMAIL_ADDR,
s.RESUME_LOCN ,
s.COMMENTS ,
s.SHIPPING_NAME ,
s.SHIPPING_CONTACT_NAME,
s.SHIPPING_ADDR ,
s.SHIPPING_ADDR1 ,
s.SHIPPING_CITY ,
s.SHIPPING_STATE,
s.SHIPPING_POSTAL ,
s.SHIPPING_CNTRY ,
s.SHIPPING_PHON_NUM,
s.SHIPPING_FAX_NUM,
s.SHIPPING_EMAIL_ADDR ,
s.STUD_PSWD ,
s.PIN ,
s.PIN_DATE,
s.ENCRYPTED ,
s.HAS_ACCESS ,
s.BILLING_NAME ,
s.BILLING_CONTACT_NAME ,
s.BILLING_ADDR ,
s.BILLING_ADDR1 ,
s.BILLING_CITY ,
s.BILLING_STATE ,
s.BILLING_POSTAL,
s.BILLING_CNTRY ,
s.BILLING_PHON_NUM ,
s.BILLING_FAX_NUM ,
s.BILLING_EMAIL_ADDR ,
s.SELF_REGISTRATION ,
s.SELF_REGISTRATION_DATE,
s.ACCESS_TO_ORG_FIN_ACT ,
s.NOTIFY_DEV_PLAN_ITEM_ADD ,
s.NOTIFY_DEV_PLAN_ITEM_MOD ,
s.NOTIFY_DEV_PLAN_ITEM_REMOVE ,
s.NOTIFY_WHEN_SUB_ITEM_COMPLETE ,
s.NOTIFY_WHEN_SUB_ITEM_FAILURE ,
s.LOCKED ,
s.PASSWORD_EXP_DATE,
s.SECURITY_QUESTION ,
s.SECURITY_ANSWER ,
s.ROLE_ID ,
s.IMAGE_ID ,
s.GENDER ,
s.PAST_SERVICE,
s.LST_UNLOCK_TSTMP,
s.LST_UPD_USR,
s.LST_UPD_TSTMP,
s.MANAGE_SUB_SP,
s.MANAGE_OWN_SP,
e.cpnt_typ_id AS cpntTypeID,
e.cpnt_id AS cpntID,
e.rev_dte AS revDate,
e.rev_num AS revNum,
e.schd_id AS schedID,
cp.cpnt_title AS cpntDesc,
e.grade,
e.compl_dte AS complDate,
e.cmpl_stat_id AS complStatID,
cs.cmpl_stat_desc AS complStatDesc,
NVL(e.total_hrs, 0) AS totalHrs,
NVL(e.credit_hrs, 0) AS creditHrs,
NVL(e.contact_hrs, 0) AS contactHrs,
NVL(e.cpe_hrs, 0) AS cpeHrs,
NVL(oi.price, 0) AS tuition,
e.inst_name AS instName,
e.comments AS eventComments,
e.es_user_name AS esUserName,
e.lst_upd_tstmp AS lstTmsp,
e.esig_meaning_code_id
|| ' '
|| e.esig_meaning_code_desc AS esigMeaningCode,
e.currency_code AS currencyCode,
cur.symbol AS currencySymbol,
cur.description,
cur.active,
cur.is_default,
cur.label_id ,
s.jl_id ,
s.job_title ,
s.super ,
s.hire_dte ,
s.term_dte ,
eeno.user_value ,
co.user_value,
e.schd_id,
sc.FACILITY_ID
FROM pa_student s,
PA_CPNT_EVTHST e,
PA_CMPL_STAT cs,
pa_fin_order_item oi,
pa_currency cur,
pa_cpnt cp,
(SELECT s.stud_id,
f.user_value
FROM PA_STUD_USER f,
pa_student s
WHERE s.stud_id = f.stud_id (+)
AND f.col_num (+) = '10'
) eeno ,
(SELECT s.stud_id,
f.user_value
FROM PA_STUD_USER f,
pa_student s
WHERE s.stud_id = f.stud_id (+)
AND f.col_num (+) = '40'
) co ,
(select sc.FACILITY_ID, ce.schd_id from PA_SCHED sc
where sc.SCHD_ID (+) = e.schd_id
) sc
WHERE e.stud_id = s.stud_id
AND e.cmpl_stat_id = cs.cmpl_stat_id
AND e.currency_code = cur.currency_code(+)
AND e.order_item_id = oi.order_item_id(+)
AND cp.cpnt_typ_id(+) = e.cpnt_typ_id
AND cp.cpnt_id(+) = e.cpnt_id
AND cp.rev_dte(+) = e.rev_dte
AND s.stud_id = eeno.stud_id(+)
AND s.stud_id = co.stud_id(+);
SELECT INDEX_ITEM_ID, INDEX_ITEM_CLASS, INDEX_ITEM_NAME, CE_NROOPE, CE_PRODUCTO, CE_OPE_DIVISA, CE_OPE_IMPORTE, CE_ESTADO, CE_FECHALTA, CE_FECHACANC, CE_CLI_NOMBRE, CE_CLI_TIPODOC, CE_CLI_NRODOC, CE_DESTINO, CE_TIPOLOGIA, CE_FECHA, CE_ESTADO_DOC, CE_WORKSTEP, CE_OBSERVACION, CE_ATRIBUTO, CE_ENVRECIB, CE_INDICE, CE_SUBINDICE, CE_NRO_SUBINDICE, CE_PARA_BROWSER, DEP_TIFNAME, DEP_VOLUMEN, OJ_NROOFI, N_IMAGENES, D_ARCHIVO, CE_PREPARADOR, N_ID_DOC, CE_DIGITALIZADOR, CE_OPERADOR , CE_REGIONAL, CE_TIPO_DOC, CE_NRODOC, CE_OPE_TIPO, CE_OPE_IMPORTE_OLD, RH_LEGAJO, RH_TIPO_DOC, FECHA_INGRESO, OJ_AMPARO_ID, OJ_ATRIBUTO, OJ_OBSERVACION, OJ_ESTADO_DOC, OJ_TIPOOFI, OJ_TIPODOC, OJ_ESTADO, OJ_PAGDEP, OJ_NRO_OFI, CE_LIQUIDADOR, CE_OFICIAL_GESTION, CE_AUT_LIQUIDACION, CE_AUT_ANALISIS, CE_BANDEJA, FORM_NOMBRE, CE_DATOS_GESTION, CE_DATOS_LIQUID, N_IMAGENES_SCAN, CE_COD_CONCEPTO, CE_BOLETO_COMPRA, CE_FACTURA, CE_DDJJ_4443, CE_PE, CE_MENS_GRUPO, CE_COD_CONCEPTO2, CE_PRIORIDAD, CE_DOCRESPALDO, CE_BOLETO_VENTA, CE_CONT_PREST, CE_DOC_TRANSP, CE_DESP_PLAZA, CE_COMA_4605, CE_LIQ_PAGO, CE_GUIA_COUR, CE_INF_CP, CE_IMP_GAN, CE_ORDCOMP, CE_COMA_3602, CE_CONST_ID, CE_FONDOS_DISP, CE_COMA_4860, CE_FECHA_NO_DISTRIBUCION, CE_ENTRADA_BANDEJA, CE_DEUDAS_SAPP, CE_FACTURA_IMPO, CE_NOTA_CRED, CE_DDJJ_43170, CE_CARTA_EXPO, CE_FACT_EBC, CE_FAC_E_CONT_ARR, CE_COMP_DESEMBOLSO, CE_COMP_GASTOS, CE_COMP_APORTE, CE_GAR_EJECUTADA, CE_FOT_PAGO, CE_FOT_ESCRIT_TRAS, CE_DOC_RESP_GASTO , CE_FOT_INTIM_EJEC, TIPO_LOTE, CE_PRESCAN_OBS, CE_PRESCAN_COMENT, CE_NRO_CAJA, CE_DESP_PLAZA_ANSEPA, CE_CARTA_CONNROOPE, CE_NOTACRED_EXPO, CE_DISC_GO, CE_DATOS_IMPO, CE_COMP_LIQ_CIA_ASEG, CE_FAC_PROV_EXT, CE_COMP_INS_ORG_OF, CE_RECLAMO_EXT , CE_COMP_GAR , CE_CERT_SSN, CE_DISCSEG_DESPACHO, CE_DISCSEG_FACTURA, CE_DISCSEG_PE , CE_DISCSEG_CARTAAP, CE_DISCSEG_PRORROGA, CE_DISCSEG_PTO56, CE_DISCSEG_NOTAAP, CE_DISCSEG_CC_BOLETO, CE_DISCSEG_CC_NOTA, CE_DISCSEG_DDJJ3473, CE_DISCSEG_CC_PE, CE_DISCSEG_CC_FAC, CE_DISCSEG_CT_PE, CE_DISCSEG_CT_NOCRED , CE_DISCSEG_CT_NOTAAP , CE_DISCSEG_CT4025_PE, CE_DISCSEG_CT4025FAC, CE_DISCSEG_COM_3602 , CE_DISCPD_PRESTMONEX , CE_DISCPD_PAGARE , CE_DISCPD_ADDENDA , CE_CLI_SEGMENTO , CE_DISC_DOCRESPORFON , CE_DISC_DDJJAYFAM , CE_DISC_DDJJREGALO, CE_DISC_DDJJ43774717 , CE_DISC_DDJJ5085 , CE_DISC_DDJJ52207 , CE_DISC_EXTRCTAEXTE , CE_DISC_DOCPARENTESC, CE_DISC_FCPROFORMA, CE_OPE_SALDO , CE_CANAL_INGRESO, CE_NROSOL_GO, CE_FECHA_LIQ_OPE, CE_DISC_CONTRATO, CE_DISC_LETRA, CE_DISC_SOL3978, CE_DISC_SOL3979 , CE_DISC_SOL3980, CE_DISC_SOL3981 , CE_DISC_SOL3982 , CE_DISC_SOL3983 , CE_TIPO_DISCREPANCIA , CE_DISC_SOLTRANSF , CE_DISC_COMA4662 , CE_DISC_Sol4982 , CE_DISC_S3909DEP, CE_DISC_S3909C4359, CE_DISC_DDJJDNR , CE_DISC_S3909D616, CE_DISC_Sol3909 , CE_DISC_COMA4237 , CE_DISC_DDJJ4762A, CE_DISC_DDJJ4762C , CE_DISC_COMA4860 , CE_DISC_CASOS447 , CE_DISC_sol3909D , CE_DISC_SOL4981 , CE_COMA_5384 , CE_APORTE_CAPITAL , CE_CID_APLI_IMPO , CE_DISC_EXPO , CE_DISC_PRESTAMO , CE_CELULA , CE_DISC_5264 , CE_DISC_DJAS , CE_CLI_OBSERVACION , IMAGEN_GO_ID , CE_TIMESTAMP_GO , CE_DISC_DOC_RESP , Disc_com_A_5630 , CE_DISC_EXCEL , CE_DISC_CONTRATOS , DISC_COM_A_5441 , DISC_COM_A_5264
INTO #temp1
FROM THUBAN_INDEXES_AUX
WHERE (
SELECT INDEX_ITEM_ID
FROM THUBAN_INDEXES_AUX
WHERE (SUBSTRING(INDEX_ITEM_ID, 1, 8)) = CONVERT(char(10),getdate(),112)
)
The error is "An expression of non-boolean type specified in a context
where a condition is expected, near ')'."
your where doesn't make any sense. Use this Where clause
.....
INTO #temp1
FROM THUBAN_INDEXES_AUX
WHERE Substring(INDEX_ITEM_ID, 1, 8) = CONVERT(CHAR(10), Getdate(), 112)
I need execute this SQL query in ZF2:
SELECT FA_VENTAS.EM_CODIGO,
FA_VENDED.VN_NOMBRE AS VENDEDOR ,
FA_CLIEN.CE_NOMBRE AS CLIENTE,
FA_TIPCLI.TC_DESCRI AS CANAL ,
MIN(FA_DETVEN.CL_NOMDEP) AS MARCA ,
IN_ITEM.IT_CODBAR AS CODBARRA ,
IN_ITEM.IT_NOMBRE AS PRODUCTO ,
TO_CHAR(FA_VENTAS.VE_FECHA,'MM')AS MESES ,
TO_CHAR(FA_VENTAS.VE_FECHA,'YYYY')AS ANIO ,
SUM(DV_SUBTOTAL-DV_VALIVA) AS VALOR ,
SUM(DV_CANPED) AS UNIDAD
FROM
DOUS.FA_VENTAS FA_VENTAS,
DOUS.FA_DETVEN FA_DETVEN,
DOUS.IN_ITEM IN_ITEM ,
DOUS.IN_CLASE IN_CLASE ,
DOUS.FA_VENDED FA_VENDED,
DOUS.FA_CLIEN FA_CLIEN,
DOUS.FA_TIPCLI FA_TIPCLI
WHERE
FA_TIPCLI.TC_CODIGO=FA_CLIEN.TC_CODIGO
AND FA_VENTAS.EM_CODIGO = FA_DETVEN.EM_CODIGO
AND FA_VENTAS.VE_CODIGO = FA_DETVEN.VE_CODIGO
AND FA_VENTAS.TP_CODIGO = FA_DETVEN.TP_CODIGO
AND FA_VENTAS.PE_CODIGO = FA_DETVEN.PE_CODIGO
AND FA_DETVEN.EM_CODIGO = IN_ITEM.EM_CODIGO
AND FA_DETVEN.IT_CODIGO = IN_ITEM.IT_CODIGO
AND IN_ITEM.EM_CODIGO = IN_CLASE.EM_CODIGO
AND IN_ITEM.CL_CODIGO = IN_CLASE.CL_CODIGO
AND FA_VENDED.VN_CODIGO=4
AND FA_VENTAS.CE_CODIGO=FA_CLIEN.CE_CODIGO
AND FA_VENTAS.EM_CODIGO = '4'
AND FA_VENTAS.TP_CODIGO = '2'
AND TRUNC(FA_VENTAS.VE_FECHA) between'01-jan-2009' and '31-jan-2009'
GROUP BY FA_VENTAS.EM_CODIGO,
FA_VENDED.VN_NOMBRE,
FA_CLIEN.CE_NOMBRE,
FA_DETVEN.CL_NOMDEP,
FA_VENTAS.VE_FECHA,
IN_ITEM.IT_CODBAR,
IN_ITEM.IT_NOMBRE,
FA_TIPCLI.TC_DESCRI
UNION ALL
SELECT FA_DEVOLU.EM_CODIGO,
FA_VENDED.VN_NOMBRE AS VENDEDOR ,
FA_CLIEN.CE_NOMBRE AS CLIENTE,
FA_TIPCLI.TC_DESCRI AS CANAL ,
MIN(FA_DETDEVOL.CL_NOMDEP)AS MARCA ,
IN_ITEM.IT_CODBAR AS CODBARRA ,
IN_ITEM.IT_NOMBRE AS PRODUCTO ,
TO_CHAR(FA_DEVOLU.DE_FECHA,'MM') AS MESES ,
TO_CHAR(FA_DEVOLU.DE_FECHA,'YYYY') AS ANIO ,
-SUM(FA_DETDEVOL.DD_SUBTOTAL- FA_DETDEVOL.DD_VALIVA) AS VALOR ,
-SUM(DD_CANTID) AS UNIDAD
FROM
DOUS.FA_DEVOLU,
DOUS.FA_DETDEVOL,
DOUS.IN_ITEM IN_ITEM ,
DOUS.IN_CLASE IN_CLASE ,
DOUS.FA_VENDED FA_VENDED,
DOUS.FA_CLIEN FA_CLIEN,
DOUS.FA_TIPCLI FA_TIPCLI
WHERE
FA_TIPCLI.TC_CODIGO=FA_CLIEN.TC_CODIGO
AND FA_DEVOLU.EM_CODIGO = FA_DETDEVOL.EM_CODIGO
AND FA_DEVOLU.DE_CODIGO = FA_DETDEVOL.DE_CODIGO
AND FA_DEVOLU.TP_CODIGO = FA_DETDEVOL.TP_CODIGO
AND FA_DETDEVOL.EM_CODIGO = IN_ITEM.EM_CODIGO
AND FA_DETDEVOL.IT_CODIGO = IN_ITEM.IT_CODIGO
AND IN_ITEM.EM_CODIGO = IN_CLASE.EM_CODIGO
AND IN_ITEM.CL_CODIGO = IN_CLASE.CL_CODIGO
AND FA_DETDEVOL.EM_CODIGO = 4
AND FA_DETDEVOL.TP_CODIGO = '2'
AND TRUNC(FA_DEVOLU.DE_FECHA) between '01-jan-2009' and '31-jan-2009'
AND FA_VENDED.VN_CODIGO=4
AND FA_DEVOLU.CE_CODIGO=FA_CLIEN.CE_CODIGO
GROUP BY FA_DEVOLU.EM_CODIGO,
FA_VENDED.VN_NOMBRE,
FA_CLIEN.CE_NOMBRE,
FA_DETDEVOL.CL_NOMDEP,
FA_DEVOLU.DE_FECHA,
IN_ITEM.IT_CODBAR,
IN_ITEM.IT_NOMBRE,
FA_TIPCLI.TC_DESCRI
but I don't understand what model, view and command use.
Please help me
With a query like this, you should use \Zend\Db\Adapter\Adapter
$sql = "SELECT SELECT FA_VENTAS.EM_CODIGO, ...";
$statement = $adapter->query($sql);
$result = $statement->execute();
hth
I do have an oracle 8 database from which I want to fetch data to SQL Server 2005. The following statement works fine, if the table on SQL Server 2005 is empty. If I run with let's say one entry missing, it does not work. Please let me know, if any additional information would be usefull!
SELECT wdmsoracle.NO
FROM (Select * from OPENQUERY(msch, 'select
actu.NO
, actu.ANNOSEQUENT
, replace(replace(dm.descript, ''Generated by modification request '', ''Modification request''), ''Pseudo ECR for WDMS-SAP interface'', ''New Drawing'')
, actu.APPRDATE
, actu.MADEDATE
, actu.MAINDRW
, actu.DESIGNGRP
, actu.ITEMID
, actu.ISSUE
, actu.DESCRIPT
, actu.DESCRIPT2
, dr.PRODUCTCODE
, mpaths.webpath as asdasd
, vpaths.webpath
FROM
WDDRAWACTU actu
, wddraw dr
, wddvfilesiss vfiles
, wddvpaths vpaths
, wddmfiles mfiles
, wddmpaths mpaths
, wdanno dm
WHERE actu.apprdate >= to_date(''01-01-05'',''dd-mm-yy'')
and actu.itemid = dr.itemid (+)
and actu.issue = dr.issue (+)
and actu.annosequent = dm.sequent (+)
and actu.itemid = vfiles.itemid (+)
and actu.issue = vfiles.issue (+)
and vfiles.pathid = vpaths.pathid
and actu.annosequent = mfiles.sequent (+)
and mfiles.pathid = mpaths.pathid')) as wdmsoracle
Where NOT EXISTS (
SELECT wdmsoracle.NO
FROM [DesignMessage_Workflow].[dbo].[WDMS] wdms, (Select * from OPENQUERY(msch, 'select
actu.NO
FROM
WDDRAWACTU actu
WHERE actu.apprdate >= to_date(''01-01-05'',''dd-mm-yy'')')) as wdmsoracle
WHERE wdms.NO = wdmsoracle.NO)
with the help of this website I was able to solve it on my own:
SELECT wdmsoracle.NO
FROM (Select * from OPENQUERY(msch, 'select
actu.NO
, actu.ANNOSEQUENT
, replace(replace(dm.descript, ''Generated by modification request '', ''Modification request''), ''Pseudo ECR for WDMS-SAP interface'', ''New Drawing'')
, actu.APPRDATE
, actu.MADEDATE
, actu.MAINDRW
, actu.DESIGNGRP
, actu.ITEMID
, actu.ISSUE
, actu.DESCRIPT
, actu.DESCRIPT2
, dr.PRODUCTCODE
, mpaths.webpath as asdasd
, vpaths.webpath
FROM
WDDRAWACTU actu
, wddraw dr
, wddvfilesiss vfiles
, wddvpaths vpaths
, wddmfiles mfiles
, wddmpaths mpaths
, wdanno dm
WHERE actu.apprdate >= to_date(''01-01-05'',''dd-mm-yy'')
and actu.itemid = dr.itemid (+)
and actu.issue = dr.issue (+)
and actu.annosequent = dm.sequent (+)
and actu.itemid = vfiles.itemid (+)
and actu.issue = vfiles.issue (+)
and vfiles.pathid = vpaths.pathid
and actu.annosequent = mfiles.sequent (+)
and mfiles.pathid = mpaths.pathid')) as wdmsoracle
Where NOT EXISTS (
SELECT wdms.NO
FROM [DesignMessage_Workflow].[dbo].[WDMS] wdms
WHERE wdms.NO = wdmsoracle.NO)