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
WITH MEMBER [Measures].[WagesToSales] as ([Measures].[Value - Fact Wages]/(([Measures].[Value]) - ([Measures].[Sales]))), FORMAT_STRING= '0.00'
SELECT [Measures].[WagesToSales] ON COLUMNS, NON EMPTY { ([Dim Date].[Date Key].[Date Key].ALLMEMBERS * [Dim Store Type].[Store Type].[Store Type].ALLMEMBERS ) } ON ROWS FROM ( SELECT ( Filter( [Dim Location].[Location Name].[Location Name].ALLMEMBERS, Instr( [Dim Location].[Location Name].currentmember.Properties( 'Member_Caption' ), 'BOSTON' ) > 0 ) ) ON COLUMNS FROM ( SELECT ( { [Dim Store Type].[Store Type].&[Boston] } ) ON COLUMNS FROM [People Dashboard 1]))
result still not displaying two decimals.
is there something that i missing?
You Try:
change
FORMAT_STRING= '0.00'
to
FORMAT_STRING='##0.00'
Try the following:
WITH
MEMBER [Measures].[WagesToSales] as
DIVIDE(
[Measures].[Value - Fact Wages]
,[Measures].[Value] - [Measures].[Sales]
)
, FORMAT_STRING= "0.00"
SELECT
[Measures].[WagesToSales] ON 0
, NON EMPTY
[Dim Date].[Date Key].[Date Key].ALLMEMBERS
* [Dim Store Type].[Store Type].[Store Type].ALLMEMBERS
ON 1
FROM
(
SELECT
Filter(
[Dim Location].[Location Name].[Location Name].ALLMEMBERS
, Instr(
[Dim Location].[Location Name].currentmember.Properties( 'Member_Caption' )
, 'BOSTON'
) > 0
)
ON 0
FROM
(
SELECT
[Dim Store Type].[Store Type].&[Boston] ON 0
FROM [People Dashboard 1]
)
);
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 have 3 calculated members defined in my SQL Server 2008 SSAS Cube..
CALCULATE;
/* Calculate Sales Volume */
CREATE MEMBER CURRENTCUBE.[Measures].[Ship Volume]
AS [Measures].[QTY SHIPPED] + [Measures].[QTY ADJUST],
FORMAT_STRING = "Standard",
NON_EMPTY_BEHAVIOR = { [QTY SHIPPED], [QTY ADJUST] },
VISIBLE = 1 , DISPLAY_FOLDER = 'Calculated Members' , ASSOCIATED_MEASURE_GROUP = 'Sales';
CREATE MEMBER CURRENTCUBE.[Measures].[Avg Price USD]
AS [Measures].[NET SALES] / [Measures].[SHIP VOLUME],
FORMAT_STRING = "Standard",
VISIBLE = 1 , DISPLAY_FOLDER = 'Calculated Members' , ASSOCIATED_MEASURE_GROUP = 'Sales' ;
CREATE MEMBER CURRENTCUBE.[Measures].[Avg Price CAD]
AS [Measures].[NET SALES CAD] / [Measures].[SHIP VOLUME],
FORMAT_STRING = "Standard",
VISIBLE = 1 , DISPLAY_FOLDER = 'Calculated Members' , ASSOCIATED_MEASURE_GROUP = 'Sales' ;
The syntax works fine, however when I look at my cube through Excel some of the values have #NUM! as the value.. not sure why this is? Is this because of divide by zero issue? How would I work around this?
Maybe check - A/B = C if B not equal 0 ? :
CALCULATE;
/* Calculate Sales Volume */
CREATE MEMBER CURRENTCUBE.[Measures].[Ship Volume]
AS [Measures].[QTY SHIPPED] + [Measures].[QTY ADJUST],
FORMAT_STRING = "Standard",
NON_EMPTY_BEHAVIOR = { [QTY SHIPPED], [QTY ADJUST] },
VISIBLE = 1 , DISPLAY_FOLDER = 'Calculated Members' , ASSOCIATED_MEASURE_GROUP = 'Sales';
CREATE MEMBER CURRENTCUBE.[Measures].[Avg Price USD]
AS Case
When IsEmpty([Measures].[SHIP VOLUME] )
THEN 0
ELSE [Measures].[NET SALES] / [Measures].[SHIP VOLUME] END,
FORMAT_STRING = "Standard",
VISIBLE = 1 , DISPLAY_FOLDER = 'Calculated Members' , ASSOCIATED_MEASURE_GROUP = 'Sales' ;
CREATE MEMBER CURRENTCUBE.[Measures].[Avg Price CAD]
AS Case
When IsEmpty([Measures].[SHIP VOLUME] )
THEN 0
ELSE [Measures].[NET SALES CAD] / [Measures].[SHIP VOLUME] END,
FORMAT_STRING = "Standard",
VISIBLE = 1 , DISPLAY_FOLDER = 'Calculated Members' , ASSOCIATED_MEASURE_GROUP = 'Sales' ;
Also you can try change IsEmpty([Measures].[SHIP VOLUME] )
to [Measures].[SHIP VOLUME]=0
EDIT
Try change this IsEmpty([Measures].[SHIP VOLUME] ) to
[Measures].[SHIP VOLUME] is null OR [Measures].[SHIP VOLUME]=0
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)