Updating multiple tables inside cursor not working - sql

I have two records in a table A. This helps me to update table 2 however the update is not been applied. This is the SQL code where I added a validation section that allow me to determinate the problem.
DECLARE abc CURSOR FOR
select d.cod_suc, d.cod_ramo_comercial, d.nro_pol, d.cod_item, d.cod_ramo_tecnico, d.cod_tarifa,
d.id_stro, d.nro_stro, d.fec_hora_reclamo, d.fec_aviso, d.fec_registro, d.fec_ingreso_contable,
d.txt_place_of_accident, d.id_substro, d.txt_nombre_cober, d.txt_direccion_bien_siniestrado, d.txt_descripcion_perdida, d.txt_cheque_a_nom, d.cod_manager_code, d.importe_pago_eq
from table1 d
where d.fec_hora_reclamo between '20140801' and '20150731'
and (d.cod_suc = 2 and d.cod_ramo_comercial = 255 and d.nro_pol = 1000001 and d.cod_item = 5)
OPEN abc
FETCH abc INTO #cod_suc, #cod_ramo_comercial, #nro_pol, #cod_item, #cod_ramo_tecnico, #cod_tarifa,
#id_stro, #nro_stro, #fec_hora_reclamo, #fec_aviso, #fec_registro, #fec_ingreso_contable,
#txt_place_of_accident, #id_substro, #txt_nombre_cober, #txt_direccion_bien_siniestrado, #txt_descripcion_perdida, #txt_cheque_a_nom, #cod_manager_code, #importe_pago_eq
WHILE (##FETCH_STATUS = 0)
BEGIN
select #varIDPV = min(id_pv), #varCodTarifa = min(cod_tarifa)
from #portfolio p
where p.cod_suc = #cod_suc and p.cod_ramo_comercial = #cod_ramo_comercial and p.Poliza = #nro_pol and p.Item = #cod_item and p.cod_ramo_tecnico = #cod_ramo_tecnico
and p.[ID Incident] IS NULL
/**************************************************************************************************************
-- Validation section
-- First record:
mid(id_pv) = 100, min(cod_tarifa) = 1
-- Second record:
mid(id_pv) = 100, min(cod_tarifa) = 1
--> Should be mid(id_pv) = 100, min(cod_tarifa) = 2
*/
select min(id_pv), min(cod_tarifa)
from #portfolio p
where p.cod_suc = #cod_suc and p.cod_ramo_comercial = #cod_ramo_comercial and p.Poliza = #nro_pol and p.Item = #cod_item and p.cod_ramo_tecnico = #cod_ramo_tecnico
and p.[ID Incident] IS NULL
/**************************************************************************************************************/
update p set p.[ID Incident] = #id_stro, p.[No. Incident] = #nro_stro,
p.[Fecha Accidente] = #fec_hora_reclamo, p.[Fecha Notificacion] = #fec_aviso, p.[Fecha Registro] = #fec_registro, p.[Fecha Pago] = #fec_ingreso_contable,
p.[Lugar Accidente] = #txt_place_of_accident, p.[ID Subsiniestro] = #id_substro, p.[Cobertura Amparo] = #txt_nombre_cober, p.[Direccion Bien Siniestrado] = #txt_direccion_bien_siniestrado, p.[Descripcion Perdida] = #txt_descripcion_perdida, p.[Pago A] = #txt_cheque_a_nom, p.[Referida] = #cod_manager_code,
[Incurrido R12] = #importe_pago_eq, [Incurrido Cerrados R12] = #importe_pago_eq
from #portfolio p
where p.cod_suc = #cod_suc and p.cod_ramo_comercial = #cod_ramo_comercial and p.Poliza = #nro_pol and p.Item = #cod_item and p.cod_ramo_tecnico = #cod_ramo_tecnico
and p.[ID Incident] IS NULL and p.id_pv = #varIDPV and p.cod_tarifa = #varCodTarifa
FETCH abc INTO #cod_suc, #cod_ramo_comercial, #nro_pol, #cod_item, #cod_ramo_tecnico, #cod_tarifa,
#id_stro, #nro_stro, #fec_hora_reclamo, #fec_aviso, #fec_registro, #fec_ingreso_contable,
#txt_place_of_accident, #id_substro, #txt_nombre_cober, #txt_direccion_bien_siniestrado, #txt_descripcion_perdida, #txt_cheque_a_nom, #cod_manager_code, #importe_pago_eq
END
CLOSE abc
DEALLOCATE abc
When I see the result, only the first record is updated.

I found the problem. I forgot to add one condition more in update (inside where). Thanks for the support

Related

MaxDB SAP SQL Missing keyword WITH on update

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')

Does Field order matter in an inner join for access SQL?

I have a query that requires ONE HUNDRED fields to be joined from one table to another. instead of manually going through the query designer, i decided to build the join using excel. When i put the code in to the SQL side of the query, then clicked designer, it choked on all 100 field comparisons and removed them. i proceeded to manually click drag the entire set of 100 field to join them all. somehow it worked. now when i look at the sql code for how access did it, it looks almost identical to my code. the only difference that i can identify is that instead of it going from A-Z, it goes Z-A.
Original Query
PARAMETERS pn TEXT (255)
,tt TEXT (255)
,sns Long
,sne Long
,ds DATETIME
,de DATETIME;
SELECT y.Short_Description1
,y.Data1
,y.Short_Description2
,y.Data2
,y.Short_Description3
,y.Data3
,y.Short_Description4
,y.Data4
,y.Short_Description5
,y.Data5
,y.Short_Description6
,y.Data6
,y.Short_Description7
,y.Data7
,y.Short_Description8
,y.Data8
,y.Short_Description9
,y.Data9
,y.Short_Description10
,y.Data10
,y.Short_Description11
,y.Data11
,y.Short_Description12
,y.Data12
,y.Short_Description13
,y.Data13
,y.Short_Description14
,y.Data14
,y.Short_Description15
,y.Data15
,y.Short_Description16
,y.Data16
,y.Short_Description17
,y.Data17
,y.Short_Description18
,y.Data18
,y.Short_Description19
,y.Data19
,y.Short_Description20
,y.Data20
,y.Short_Description21
,y.Data21
,y.Short_Description22
,y.Data22
,y.Short_Description23
,y.Data23
,y.Short_Description24
,y.Data24
,y.Short_Description25
,y.Data25
,y.Short_Description26
,y.Data26
,y.Short_Description27
,y.Data27
,y.Short_Description28
,y.Data28
,y.Short_Description29
,y.Data29
,y.Short_Description30
,y.Data30
,y.Short_Description31
,y.Data31
,y.Short_Description32
,y.Data32
,y.Short_Description33
,y.Data33
,y.Short_Description34
,y.Data34
,y.Short_Description35
,y.Data35
,y.Short_Description36
,y.Data36
,y.Short_Description37
,y.Data37
,y.Short_Description38
,y.Data38
,y.Short_Description39
,y.Data39
,y.Short_Description40
,y.Data40
,y.Short_Description41
,y.Data41
,y.Short_Description42
,y.Data42
,y.Short_Description43
,y.Data43
,y.Short_Description44
,y.Data44
,y.Short_Description45
,y.Data45
,y.Short_Description46
,y.Data46
,y.Short_Description47
,y.Data47
,y.Short_Description48
,y.Data48
,y.Short_Description49
,y.Data49
,y.Short_Description50
,y.Data50
,y.Short_Description51
,y.Data51
,y.Short_Description52
,y.Data52
,y.Short_Description53
,y.Data53
,y.Short_Description54
,y.Data54
,y.Short_Description55
,y.Data55
,y.Short_Description56
,y.Data56
,y.Short_Description57
,y.Data57
,y.Short_Description58
,y.Data58
,y.Short_Description59
,y.Data59
,y.Short_Description60
,y.Data60
,y.Short_Description61
,y.Data61
,y.Short_Description62
,y.Data62
,y.Short_Description63
,y.Data63
,y.Short_Description64
,y.Data64
,y.Short_Description65
,y.Data65
,y.Short_Description66
,y.Data66
,y.Short_Description67
,y.Data67
,y.Short_Description68
,y.Data68
,y.Short_Description69
,y.Data69
,y.Short_Description70
,y.Data70
,y.Short_Description71
,y.Data71
,y.Short_Description72
,y.Data72
,y.Short_Description73
,y.Data73
,y.Short_Description74
,y.Data74
,y.Short_Description75
,y.Data75
,y.Short_Description76
,y.Data76
,y.Short_Description77
,y.Data77
,y.Short_Description78
,y.Data78
,y.Short_Description79
,y.Data79
,y.Short_Description80
,y.Data80
,y.Short_Description81
,y.Data81
,y.Short_Description82
,y.Data82
,y.Short_Description83
,y.Data83
,y.Short_Description84
,y.Data84
,y.Short_Description85
,y.Data85
,y.Short_Description86
,y.Data86
,y.Short_Description87
,y.Data87
,y.Short_Description88
,y.Data88
,y.Short_Description89
,y.Data89
,y.Short_Description90
,y.Data90
,y.Short_Description91
,y.Data91
,y.Short_Description92
,y.Data92
,y.Short_Description93
,y.Data93
,y.Short_Description94
,y.Data94
,y.Short_Description95
,y.Data95
,y.Short_Description96
,y.Data96
,y.Short_Description97
,y.Data97
,y.Short_Description98
,y.Data98
,y.Short_Description99
,y.Data99
,y.Short_Description100
,y.Data100
,x.rownum
FROM qryIndividualTestData100Descriptions AS x
INNER JOIN IndividualTestData100 AS y ON (x.Short_Description1 =
y.Short_Description1)
AND (x.Short_Description2 = y.Short_Description2)
AND (x.Short_Description3 = y.Short_Description3)
AND (x.Short_Description4 = y.Short_Description4)
AND (x.Short_Description5 = y.Short_Description5)
AND (x.Short_Description6 = y.Short_Description6)
AND (x.Short_Description7 = y.Short_Description7)
AND (x.Short_Description8 = y.Short_Description8)
AND (x.Short_Description9 = y.Short_Description9)
AND (x.Short_Description10 = y.Short_Description10)
AND (x.Short_Description11 = y.Short_Description11)
AND (x.Short_Description12 = y.Short_Description12)
AND (x.Short_Description13 = y.Short_Description13)
AND (x.Short_Description14 = y.Short_Description14)
AND (x.Short_Description15 = y.Short_Description15)
AND (x.Short_Description16 = y.Short_Description16)
AND (x.Short_Description17 = y.Short_Description17)
AND (x.Short_Description18 = y.Short_Description18)
AND (x.Short_Description19 = y.Short_Description19)
AND (x.Short_Description20 = y.Short_Description20)
AND (x.Short_Description21 = y.Short_Description21)
AND (x.Short_Description22 = y.Short_Description22)
AND (x.Short_Description23 = y.Short_Description23)
AND (x.Short_Description24 = y.Short_Description24)
AND (x.Short_Description25 = y.Short_Description25)
AND (x.Short_Description26 = y.Short_Description26)
AND (x.Short_Description27 = y.Short_Description27)
AND (x.Short_Description28 = y.Short_Description28)
AND (x.Short_Description29 = y.Short_Description29)
AND (x.Short_Description30 = y.Short_Description30)
AND (x.Short_Description31 = y.Short_Description31)
AND (x.Short_Description32 = y.Short_Description32)
AND (x.Short_Description33 = y.Short_Description33)
AND (x.Short_Description34 = y.Short_Description34)
AND (x.Short_Description35 = y.Short_Description35)
AND (x.Short_Description36 = y.Short_Description36)
AND (x.Short_Description37 = y.Short_Description37)
AND (x.Short_Description38 = y.Short_Description38)
AND (x.Short_Description39 = y.Short_Description39)
AND (x.Short_Description40 = y.Short_Description40)
AND (x.Short_Description41 = y.Short_Description41)
AND (x.Short_Description42 = y.Short_Description42)
AND (x.Short_Description43 = y.Short_Description43)
AND (x.Short_Description44 = y.Short_Description44)
AND (x.Short_Description45 = y.Short_Description45)
AND (x.Short_Description46 = y.Short_Description46)
AND (x.Short_Description47 = y.Short_Description47)
AND (x.Short_Description48 = y.Short_Description48)
AND (x.Short_Description49 = y.Short_Description49)
AND (x.Short_Description50 = y.Short_Description50)
AND (x.Short_Description51 = y.Short_Description51)
AND (x.Short_Description52 = y.Short_Description52)
AND (x.Short_Description53 = y.Short_Description53)
AND (x.Short_Description54 = y.Short_Description54)
AND (x.Short_Description55 = y.Short_Description55)
AND (x.Short_Description56 = y.Short_Description56)
AND (x.Short_Description57 = y.Short_Description57)
AND (x.Short_Description58 = y.Short_Description58)
AND (x.Short_Description59 = y.Short_Description59)
AND (x.Short_Description60 = y.Short_Description60)
AND (x.Short_Description61 = y.Short_Description61)
AND (x.Short_Description62 = y.Short_Description62)
AND (x.Short_Description63 = y.Short_Description63)
AND (x.Short_Description64 = y.Short_Description64)
AND (x.Short_Description65 = y.Short_Description65)
AND (x.Short_Description66 = y.Short_Description66)
AND (x.Short_Description67 = y.Short_Description67)
AND (x.Short_Description68 = y.Short_Description68)
AND (x.Short_Description69 = y.Short_Description69)
AND (x.Short_Description70 = y.Short_Description70)
AND (x.Short_Description71 = y.Short_Description71)
AND (x.Short_Description72 = y.Short_Description72)
AND (x.Short_Description73 = y.Short_Description73)
AND (x.Short_Description74 = y.Short_Description74)
AND (x.Short_Description75 = y.Short_Description75)
AND (x.Short_Description76 = y.Short_Description76)
AND (x.Short_Description77 = y.Short_Description77)
AND (x.Short_Description78 = y.Short_Description78)
AND (x.Short_Description79 = y.Short_Description79)
AND (x.Short_Description80 = y.Short_Description80)
AND (x.Short_Description81 = y.Short_Description81)
AND (x.Short_Description82 = y.Short_Description82)
AND (x.Short_Description83 = y.Short_Description83)
AND (x.Short_Description84 = y.Short_Description84)
AND (x.Short_Description85 = y.Short_Description85)
AND (x.Short_Description86 = y.Short_Description86)
AND (x.Short_Description87 = y.Short_Description87)
AND (x.Short_Description88 = y.Short_Description88)
AND (x.Short_Description89 = y.Short_Description89)
AND (x.Short_Description90 = y.Short_Description90)
AND (x.Short_Description91 = y.Short_Description91)
AND (x.Short_Description92 = y.Short_Description92)
AND (x.Short_Description93 = y.Short_Description93)
AND (x.Short_Description94 = y.Short_Description94)
AND (x.Short_Description95 = y.Short_Description95)
AND (x.Short_Description96 = y.Short_Description96)
AND (x.Short_Description97 = y.Short_Description97)
AND (x.Short_Description98 = y.Short_Description98)
AND (x.Short_Description99 = y.Short_Description99)
AND (x.Short_Description100 = y.Short_Description100)
WHERE (
((y.[Part_Number]) LIKE [pn] & "*" & [tt])
AND (
(y.[Serial_Number]) >= [sns]
AND (y.[Serial_Number]) <= [sne]
)
AND (
(y.[Test_Date]) >= [ds]
AND (y.[Test_Date]) <= [de]
)
);
Access Generated version
PARAMETERS pn TEXT (255)
,tt TEXT (255)
,sns Long
,sne Long
,ds DATETIME
,de DATETIME;
SELECT y.Short_Description1
,y.Data1
,y.Short_Description2
,y.Data2
,y.Short_Description3
,y.Data3
,y.Short_Description4
,y.Data4
,y.Short_Description5
,y.Data5
,y.Short_Description6
,y.Data6
,y.Short_Description7
,y.Data7
,y.Short_Description8
,y.Data8
,y.Short_Description9
,y.Data9
,y.Short_Description10
,y.Data10
,y.Short_Description11
,y.Data11
,y.Short_Description12
,y.Data12
,y.Short_Description13
,y.Data13
,y.Short_Description14
,y.Data14
,y.Short_Description15
,y.Data15
,y.Short_Description16
,y.Data16
,y.Short_Description17
,y.Data17
,y.Short_Description18
,y.Data18
,y.Short_Description19
,y.Data19
,y.Short_Description20
,y.Data20
,y.Short_Description21
,y.Data21
,y.Short_Description22
,y.Data22
,y.Short_Description23
,y.Data23
,y.Short_Description24
,y.Data24
,y.Short_Description25
,y.Data25
,y.Short_Description26
,y.Data26
,y.Short_Description27
,y.Data27
,y.Short_Description28
,y.Data28
,y.Short_Description29
,y.Data29
,y.Short_Description30
,y.Data30
,y.Short_Description31
,y.Data31
,y.Short_Description32
,y.Data32
,y.Short_Description33
,y.Data33
,y.Short_Description34
,y.Data34
,y.Short_Description35
,y.Data35
,y.Short_Description36
,y.Data36
,y.Short_Description37
,y.Data37
,y.Short_Description38
,y.Data38
,y.Short_Description39
,y.Data39
,y.Short_Description40
,y.Data40
,y.Short_Description41
,y.Data41
,y.Short_Description42
,y.Data42
,y.Short_Description43
,y.Data43
,y.Short_Description44
,y.Data44
,y.Short_Description45
,y.Data45
,y.Short_Description46
,y.Data46
,y.Short_Description47
,y.Data47
,y.Short_Description48
,y.Data48
,y.Short_Description49
,y.Data49
,y.Short_Description50
,y.Data50
,y.Short_Description51
,y.Data51
,y.Short_Description52
,y.Data52
,y.Short_Description53
,y.Data53
,y.Short_Description54
,y.Data54
,y.Short_Description55
,y.Data55
,y.Short_Description56
,y.Data56
,y.Short_Description57
,y.Data57
,y.Short_Description58
,y.Data58
,y.Short_Description59
,y.Data59
,y.Short_Description60
,y.Data60
,y.Short_Description61
,y.Data61
,y.Short_Description62
,y.Data62
,y.Short_Description63
,y.Data63
,y.Short_Description64
,y.Data64
,y.Short_Description65
,y.Data65
,y.Short_Description66
,y.Data66
,y.Short_Description67
,y.Data67
,y.Short_Description68
,y.Data68
,y.Short_Description69
,y.Data69
,y.Short_Description70
,y.Data70
,y.Short_Description71
,y.Data71
,y.Short_Description72
,y.Data72
,y.Short_Description73
,y.Data73
,y.Short_Description74
,y.Data74
,y.Short_Description75
,y.Data75
,y.Short_Description76
,y.Data76
,y.Short_Description77
,y.Data77
,y.Short_Description78
,y.Data78
,y.Short_Description79
,y.Data79
,y.Short_Description80
,y.Data80
,y.Short_Description81
,y.Data81
,y.Short_Description82
,y.Data82
,y.Short_Description83
,y.Data83
,y.Short_Description84
,y.Data84
,y.Short_Description85
,y.Data85
,y.Short_Description86
,y.Data86
,y.Short_Description87
,y.Data87
,y.Short_Description88
,y.Data88
,y.Short_Description89
,y.Data89
,y.Short_Description90
,y.Data90
,y.Short_Description91
,y.Data91
,y.Short_Description92
,y.Data92
,y.Short_Description93
,y.Data93
,y.Short_Description94
,y.Data94
,y.Short_Description95
,y.Data95
,y.Short_Description96
,y.Data96
,y.Short_Description97
,y.Data97
,y.Short_Description98
,y.Data98
,y.Short_Description99
,y.Data99
,y.Short_Description100
,y.Data100
,x.rownum
FROM qryIndividualTestData100Descriptions AS x
INNER JOIN individualtestdata100 AS y ON (x.Short_Description100 =
y.Short_Description100)
AND (x.Short_Description99 = y.Short_Description99)
AND (x.Short_Description98 = y.Short_Description98)
AND (x.Short_Description97 = y.Short_Description97)
AND (x.Short_Description96 = y.Short_Description96)
AND (x.Short_Description95 = y.Short_Description95)
AND (x.Short_Description94 = y.Short_Description94)
AND (x.Short_Description93 = y.Short_Description93)
AND (x.Short_Description92 = y.Short_Description92)
AND (x.Short_Description91 = y.Short_Description91)
AND (x.Short_Description90 = y.Short_Description90)
AND (x.Short_Description89 = y.Short_Description89)
AND (x.Short_Description88 = y.Short_Description88)
AND (x.Short_Description87 = y.Short_Description87)
AND (x.Short_Description86 = y.Short_Description86)
AND (x.Short_Description85 = y.Short_Description85)
AND (x.Short_Description84 = y.Short_Description84)
AND (x.Short_Description83 = y.Short_Description83)
AND (x.Short_Description82 = y.Short_Description82)
AND (x.Short_Description81 = y.Short_Description81)
AND (x.Short_Description80 = y.Short_Description80)
AND (x.Short_Description79 = y.Short_Description79)
AND (x.Short_Description78 = y.Short_Description78)
AND (x.Short_Description77 = y.Short_Description77)
AND (x.Short_Description76 = y.Short_Description76)
AND (x.Short_Description75 = y.Short_Description75)
AND (x.Short_Description74 = y.Short_Description74)
AND (x.Short_Description73 = y.Short_Description73)
AND (x.Short_Description72 = y.Short_Description72)
AND (x.Short_Description71 = y.Short_Description71)
AND (x.Short_Description70 = y.Short_Description70)
AND (x.Short_Description69 = y.Short_Description69)
AND (x.Short_Description68 = y.Short_Description68)
AND (x.Short_Description67 = y.Short_Description67)
AND (x.Short_Description66 = y.Short_Description66)
AND (x.Short_Description65 = y.Short_Description65)
AND (x.Short_Description64 = y.Short_Description64)
AND (x.Short_Description63 = y.Short_Description63)
AND (x.Short_Description62 = y.Short_Description62)
AND (x.Short_Description61 = y.Short_Description61)
AND (x.Short_Description60 = y.Short_Description60)
AND (x.Short_Description59 = y.Short_Description59)
AND (x.Short_Description58 = y.Short_Description58)
AND (x.Short_Description57 = y.Short_Description57)
AND (x.Short_Description56 = y.Short_Description56)
AND (x.Short_Description55 = y.Short_Description55)
AND (x.Short_Description54 = y.Short_Description54)
AND (x.Short_Description53 = y.Short_Description53)
AND (x.Short_Description52 = y.Short_Description52)
AND (x.Short_Description51 = y.Short_Description51)
AND (x.Short_Description50 = y.Short_Description50)
AND (x.Short_Description49 = y.Short_Description49)
AND (x.Short_Description48 = y.Short_Description48)
AND (x.Short_Description47 = y.Short_Description47)
AND (x.Short_Description46 = y.Short_Description46)
AND (x.Short_Description45 = y.Short_Description45)
AND (x.Short_Description44 = y.Short_Description44)
AND (x.Short_Description43 = y.Short_Description43)
AND (x.Short_Description42 = y.Short_Description42)
AND (x.Short_Description41 = y.Short_Description41)
AND (x.Short_Description40 = y.Short_Description40)
AND (x.Short_Description39 = y.Short_Description39)
AND (x.Short_Description38 = y.Short_Description38)
AND (x.Short_Description37 = y.Short_Description37)
AND (x.Short_Description36 = y.Short_Description36)
AND (x.Short_Description35 = y.Short_Description35)
AND (x.Short_Description34 = y.Short_Description34)
AND (x.Short_Description33 = y.Short_Description33)
AND (x.Short_Description32 = y.Short_Description32)
AND (x.Short_Description31 = y.Short_Description31)
AND (x.Short_Description30 = y.Short_Description30)
AND (x.Short_Description29 = y.Short_Description29)
AND (x.Short_Description28 = y.Short_Description28)
AND (x.Short_Description27 = y.Short_Description27)
AND (x.Short_Description26 = y.Short_Description26)
AND (x.Short_Description25 = y.Short_Description25)
AND (x.Short_Description24 = y.Short_Description24)
AND (x.Short_Description23 = y.Short_Description23)
AND (x.Short_Description22 = y.Short_Description22)
AND (x.Short_Description21 = y.Short_Description21)
AND (x.Short_Description20 = y.Short_Description20)
AND (x.Short_Description19 = y.Short_Description19)
AND (x.Short_Description18 = y.Short_Description18)
AND (x.Short_Description17 = y.Short_Description17)
AND (x.Short_Description16 = y.Short_Description16)
AND (x.Short_Description15 = y.Short_Description15)
AND (x.Short_Description14 = y.Short_Description14)
AND (x.Short_Description13 = y.Short_Description13)
AND (x.Short_Description12 = y.Short_Description12)
AND (x.Short_Description11 = y.Short_Description11)
AND (x.Short_Description10 = y.Short_Description10)
AND (x.Short_Description9 = y.Short_Description9)
AND (x.Short_Description8 = y.Short_Description8)
AND (x.Short_Description7 = y.Short_Description7)
AND (x.Short_Description6 = y.Short_Description6)
AND (x.Short_Description5 = y.Short_Description5)
AND (x.Short_Description4 = y.Short_Description4)
AND (x.Short_Description3 = y.Short_Description3)
AND (x.Short_Description2 = y.Short_Description2)
AND (x.Short_Description1 = y.Short_Description1)
WHERE (
((y.Part_Number) LIKE [pn] & "*" & [tt])
AND (
(y.Serial_Number) >= [sns]
AND (y.Serial_Number) <= [sne]
)
AND (
(y.Test_Date) >= [ds]
AND (y.Test_Date) <= [de]
)
);
Why does access choke on the query?

Apache ignite query not working well with index

I upload the data in ignite 3 cache and total data around 1 million in all 3 caches.while i run query on it i got result in 1s and its generate below query plan
SELECT DISTINCT
A3.VAL2 AS __C0
FROM DPHAF.DPHAF A1
/* DPHAF.DPHAF.__SCAN_ */
/* WHERE (A1.VAL0 = 'dg~')
AND ((A1.PROP6 = '1oh~#has_single_bond')
AND (A1.PROP0 = '4xm~#type'))
*/
INNER JOIN DS_AF.DS_AF S1
/* DS_AF."prop_asc_entity_asc_elem_asc_typ_asc_idx": PROP = A1.PROP6
AND ENTITY = A1.ENTRY
*/
ON 1=1
/* WHERE (A1.PROP6 = S1.PROP)
AND (A1.ENTRY = S1.ENTITY)
*/
INNER JOIN DPHAF.DPHAF A2
/* DPHAF."entry_asc_idx": ENTRY = S1.ELEM */
ON 1=1
/* WHERE (S1.ELEM = A2.ENTRY)
AND ((A2.PROP0 = '4xm~#type')
AND ((A2.PROP6 = '1oh~#has_single_bond')
AND (A2.VAL0 = '7a~')))
*/
INNER JOIN DS_AF.DS_AF S2
/* DS_AF."prop_asc_entity_asc_elem_asc_typ_asc_idx": PROP = A2.PROP6
AND ENTITY = A2.ENTRY
*/
ON 1=1
/* WHERE (A2.PROP6 = S2.PROP)
AND (A2.ENTRY = S2.ENTITY)
*/
INNER JOIN DPHAF.DPHAF A3
/* DPHAF."entry_asc_idx": ENTRY = S2.ELEM */
ON 1=1
WHERE (A3.PROP2 = '1oh~#is_atom_of')
AND ((A3.VAL0 = '7a~')
AND ((A3.PROP0 = '4xm~#type')
AND ((S2.ELEM = A3.ENTRY)
AND ((A2.PROP6 = S2.PROP)
AND ((A2.PROP6 = '1oh~#has_single_bond')
AND ((A2.ENTRY = S2.ENTITY)
AND ((A2.VAL0 = '7a~')
AND ((A2.PROP0 = '4xm~#type')
AND ((S1.ELEM = A2.ENTRY)
AND ((A1.PROP6 = S1.PROP)
AND ((A1.PROP6 = '1oh~#has_single_bond')
AND ((A1.ENTRY = S1.ENTITY)
AND ((A1.PROP0 = '4xm~#type')
AND (A1.VAL0 = 'dg~'))))))))))))))
LIMIT 1000
SELECT DISTINCT
__C0 AS VAL2
FROM PUBLIC.__T0
/* DPHAF."merge_scan" */
LIMIT 1000
as you notice there is full cache scan here /* DPHAF.DPHAF.__SCAN_ */
After that when we add index on DPHAF group index it will give us below plan
SELECT
A1.VAL2 AS __C0
FROM DPHAF.DPHAF A1
/* DPHAF."prop0_asc_val0_asc_idx": VAL0 = '7a~'
AND PROP0 = '4xm~#type'
*/
/* WHERE (A1.PROP0 = '4xm~#type')
AND ((A1.PROP2 = '1oh~#is_atom_of')
AND ((A1.VAL0 = '7a~')
AND ((A1.VAL5 = '3')
AND ((A1.PROP8 = '1oh~#has_double_bond')
AND (A1.PROP6 = '1oh~#has_single_bond')))))
*/
INNER JOIN DPHAF.DPHAF A3
/* DPHAF."prop0_asc_val0_asc_idx": VAL0 = '7a~'
AND PROP0 = '4xm~#type'
*/
ON 1=1
/* WHERE (A3.PROP0 = '4xm~#type')
AND ((A3.VAL5 = '1')
AND (A3.VAL0 = '7a~'))
*/
INNER JOIN DPHAF.DPHAF A4
/* DPHAF."prop0_asc_val0_asc_idx": VAL0 = '562~'
AND PROP0 = '4xm~#type'
*/
ON 1=1
/* WHERE (A4.PROP0 = '4xm~#type')
AND ((A4.VAL5 = '1')
AND (A4.VAL0 = '562~'))
*/
INNER JOIN DS_AF.DS_AF S1
/* DS_AF."prop_asc_entity_asc_elem_asc_typ_asc_idx": PROP = A1.PROP6
AND ENTITY = A1.ENTRY
*/
ON 1=1
/* WHERE (A1.PROP6 = S1.PROP)
AND (A1.ENTRY = S1.ENTITY)
*/
INNER JOIN DPHAF.DPHAF A2
/* DPHAF."entry_asc_idx": ENTRY = S1.ELEM */
ON 1=1
/* WHERE (S1.ELEM = A2.ENTRY)
AND ((A2.VAL5 = '1')
AND (A2.VAL0 = '562~'))
*/
INNER JOIN DS_AF.DS_AF S2
/* DS_AF."prop_asc_elem_asc_entity_asc_typ_asc_idx": ELEM = A3.ENTRY
AND PROP = A1.PROP6
AND ENTITY = A1.ENTRY
*/
ON 1=1
/* WHERE (A1.ENTRY = S2.ENTITY)
AND ((S2.ELEM = A3.ENTRY)
AND (A1.PROP6 = S2.PROP))
*/
INNER JOIN DS_AF.DS_AF D1
/* DS_AF."prop_asc_elem_asc_entity_asc_typ_asc_idx": ELEM = A4.ENTRY
AND PROP = A1.PROP8
AND ENTITY = A1.ENTRY
*/
ON 1=1
WHERE (A4.VAL5 = '1')
AND ((A4.VAL0 = '562~')
AND ((A4.PROP0 = '4xm~#type')
AND ((D1.ELEM = A4.ENTRY)
AND ((A1.PROP8 = D1.PROP)
AND ((A1.PROP8 = '1oh~#has_double_bond')
AND ((A1.ENTRY = D1.ENTITY)
AND ((A3.VAL5 = '1')
AND ((A3.VAL0 = '7a~')
AND ((A3.PROP0 = '4xm~#type')
AND ((S2.ELEM = A3.ENTRY)
AND ((A1.PROP6 = S2.PROP)
AND ((A1.ENTRY = S2.ENTITY)
AND ((A2.VAL5 = '1')
AND ((A2.VAL0 = '562~')
AND ((S1.ELEM = A2.ENTRY)
AND ((A1.PROP6 = S1.PROP)
AND ((A1.PROP6 = '1oh~#has_single_bond')
AND ((A1.ENTRY = S1.ENTITY)
AND ((A1.VAL5 = '3')
AND ((A1.VAL0 = '7a~')
AND ((A1.PROP2 = '1oh~#is_atom_of')
AND (A1.PROP0 = '4xm~#type'))))))))))))))))))))))
SELECT
__C0 AS VAL2
FROM PUBLIC.__T0
/* DPHAF."merge_scan" */
Here you can see we dont have full scan of DPHAF but my query is running for soo long or infinite so am i do anything wrong?
Thanks
It is best if you ask this question at Ignite user forum. It requires debugging to get to the bottom of it.

Full outer join very slow

I have two tables. One is todays prices and one is yesterdays prices. There is a job which updates each table over night. Yesterdays prices is a copy of todays before it gets updated.
I am trying to create a table which shows the differences between the tables.
To do this I am using a full outer join. I am filtering down my criteria to make it faster as both tables are over 48 million rows.
My current code is like this.
WITH differ AS
(
SELECT
tAP.CustomerID, tAP.ProductID, yAP.CustomerID AS 'Yest_CustomerID', yAP.ProductID AS 'Yest_ProductID',
tAP.PDG, tAP.DiscPct1, tAP.DiscPct2,
yAP.DiscPct1 AS 'Yest_DiscPct1',
yAP.DiscPct2 AS 'Yest_DiscPct2',
CONVERT(DECIMAL(18,2),tAP.DiscPct1 - yAP.DiscPct1) AS 'DiscPct1_Difference',
CONVERT(DECIMAL(18,2),tAP.DiscPct2 - yAP.DiscPct2) AS 'DiscPct2_Difference',
tAP.internalSPANumber, yAP.internalSPANumber AS 'Yest_InternalSPANumber', tAP.SPAUniqueReference,
tAP.Project,
tAP.ExpiryDate,tAP.Subaddress, tAP.PriceType, yAP.PriceType AS 'Yest_PriceType', tAP.ListPrice,
tAP.NettPrice, yAP.NettPrice AS 'Yest_NettPrice',
CONVERT(DECIMAL(18,2),tAP.NettPrice- yAP.NettPrice) AS 'NettPrice_Difference'
FROM tbl_Prices tAP FULL OUTER JOIN tbl_Prices_Yesterday yAP ON tAP.CustomerId = yAP.CustomerID AND tAP.ProductID = yAP.ProductID
AND tAP.PDG = yAP.PDG AND tAP.Project = yAP.Project AND tAP.PriceType = yAP.PriceType
WHERE (((tAP.DiscPct1 <> yAP.DiscPct1)
OR (tAP.DiscPct2 <> yAP.DiscPct2)
OR (yAP.CustomerID IS NULL)
OR (tAP.CustomerID IS NULL)
OR (tAP.NettPrice <> yAP.NettPrice)
OR (tAP.InternalSPANumber <> yAP.InternalSPANumber))
AND
(
tAP.ProductID = '10238610' OR tAP.ProductID = '10238620'
OR tAP.ProductID = '10238621' OR tAP.ProductID = '10238687'
OR tAP.ProductID = '10238688' OR yAP.ProductID = '10238610'
OR yAP.ProductID = '10238620' OR yAP.ProductID = '10238621'
OR yAP.ProductID = '10238687' OR yAP.ProductID = '10238688')
)
)
SELECT * INTO tbl_Difference FROM differ
Anyway to make this faster?
Can you filter the 2 large tables before you try to join them using AND filter in your where?
WITH tAPcte AS
(
SELECT * -- fields you need
FROM tbl_Prices
WHERE ProductID IN ('10238610',
'10238620',
'10238621',
'10238687',
'10238688')
),
yAPcte AS
(
SELECT * -- fields you need
FROM tbl_Prices_Yesterday
WHERE ProductID IN ('10238610',
'10238620',
'10238621',
'10238687',
'10238688')
)
differ AS
(
SELECT
tAP.CustomerID, tAP.ProductID, yAP.CustomerID AS 'Yest_CustomerID', yAP.ProductID AS 'Yest_ProductID',
tAP.PDG, tAP.DiscPct1, tAP.DiscPct2,
yAP.DiscPct1 AS 'Yest_DiscPct1',
yAP.DiscPct2 AS 'Yest_DiscPct2',
CONVERT(DECIMAL(18,2),tAP.DiscPct1 - yAP.DiscPct1) AS 'DiscPct1_Difference',
CONVERT(DECIMAL(18,2),tAP.DiscPct2 - yAP.DiscPct2) AS 'DiscPct2_Difference',
tAP.internalSPANumber, yAP.internalSPANumber AS 'Yest_InternalSPANumber', tAP.SPAUniqueReference,
tAP.Project,
tAP.ExpiryDate,tAP.Subaddress, tAP.PriceType, yAP.PriceType AS 'Yest_PriceType', tAP.ListPrice,
tAP.NettPrice, yAP.NettPrice AS 'Yest_NettPrice',
CONVERT(DECIMAL(18,2),tAP.NettPrice- yAP.NettPrice) AS 'NettPrice_Difference'
FROM tAPcte tAP FULL OUTER JOIN yAPcte yAP ON tAP.CustomerId = yAP.CustomerID AND tAP.ProductID = yAP.ProductID
AND tAP.PDG = yAP.PDG AND tAP.Project = yAP.Project AND tAP.PriceType = yAP.PriceType
WHERE (((tAP.DiscPct1 <> yAP.DiscPct1)
OR (tAP.DiscPct2 <> yAP.DiscPct2)
OR (yAP.CustomerID IS NULL)
OR (tAP.CustomerID IS NULL)
OR (tAP.NettPrice <> yAP.NettPrice)
OR (tAP.InternalSPANumber <> yAP.InternalSPANumber))
)
SELECT * INTO tbl_Difference FROM differ

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!