Problem translate query from Access to MySQL
Hi there, I hope for your help.
I’m very sorry disturb, but I need translate SQL Query from Access DB to MySQL DB.
I need your helping because when execute SQL query in the Access DB the number of records imported is 204.786 and don’t have Orig_Int
null value.
When execute SQL query in the MySQL DB the number of records imported is 275.333 and 1.588 records when the field Orig_Int
is null, why?
All tables are identical in all databases, but in MyQL I have 70.547 rows extra.
I think problem with function aggregate in MySQL.
Can you help me?
Thanks in advance.
This is SQL Query in Access DB (output 204.786 rows and don’t have Orig_Int
null value ):
INSERT INTO _Reg_L ( CFT_Cod, Orig_Int, DtInter, [A20 (Min)], A16_17 )
SELECT
Org.CFT_Cod,
IIf([R].[Art]='51M','51M',IIf([R].[Art]='450','MT','BT')) AS Orig_Int,
CDate(CStr(Day([R]![DtInter]))+'/'+CStr(Month([R]![DtInter]))+'/'+CStr(Year([R]![DtInter]))) AS DtInter,
Sum(IIf([R].[CDI]='P',[R].[C_BT]*[R].[DNF8 (sec)]/60,0)) AS A20,
Sum(IIf([R].[CDI] In ('P','B'),[R].[C_BT],0)) AS A16_17
FROM
_Reg AS R
INNER JOIN Org ON R.CFT_Cod = Org.CFT_Cod_old
WHERE
((R.Pre='N' Or R.Pre Is Null) AND
R.E_Cod Like 'T*' AND
R.C_I<>'F' AND
R.Pert='N' AND
R.Art In ('51M','450','41B','460','475','476'))
OR
((R.Pre='N' Or R.Pre Is Null) AND
R.E_Cod Like 'T*' AND
R.C_I<>'F' AND
R.Pert='N' AND
R.Art In ('51M','450','41B','460','475','476'))
GROUP BY
Org.CFT_Cod,
IIf([R].[Art]='51M','51M',IIf([R].[Art]='450','MT','BT')),
CDate(CStr(Day([R]![DtInter]))+'/'+CStr(Month([R]![DtInter]))+'/'+CStr(Year([R]![DtInter])))"
HAVING
(((Sum(IIf([R].[CDI]='P',[R].[C_BT]*[R].[DNF8 (sec)]/60,0)))>0))
OR
(((Sum(IIf([R].[CDI] In ('P','B'),[R].[C_BT],0)))>0))"
This is SQL Query translate from Access DB to MySQL DB and execute in MySQL DB (output 275.333 rows and 1.588 records when the field Orig_Int
is null ):
INSERT INTO
_Reg_L
(
xID
, DtUpdate
, CFT_Cod
, Orig_Int
, DtInter
, `A20(Min)`
, A16_17
)
SELECT
0
, R.DtUpdate
, C.CFT_Cod
, CASE
WHEN (R.Art='51M' AND R.CDI In('P','B')) THEN '51M'
WHEN (R.Art='450' AND R.CDI In('P','B')) THEN 'MT'
WHEN (R.Art NOT IN ('51M','450') AND R.CDI In('P','B')) THEN 'BT'
END Orig_Int
, STR_TO_DATE(R.DtInter, '%Y-%m-%d %H:%i:%s') DtInter
, SUM(IF(R.CDI='P', R.C_BT * `DNF8 (sec)`/60, 0)) A20
, SUM(IF(R.CDI In('P','B'), R.C_BT, 0)) A16_17
FROM _Reg R
INNER JOIN Org C ON R.CFT_Cod = Org.CFT_Cod_old
WHERE 1 AND
(
(R.Pre='N' Or IsNull(R.Pre))
AND R.E_Cod Like 'T%'
AND R.C_I<>'F'
AND R.Pert='N'
AND R.Art In ('51M','450','41B','460','475','476')
)
GROUP BY
C.CFT_Cod
, Orig_Int
, DtInter
HAVING A20 > 0 OR A16_17 > 0
ORDER BY DtInter DESC;