I'm doing a procedure in which I create a temporary table and fill it with the result of a query, or at least that's what I'm trying to do.
I have the following script:
CREATE TEMPORARY table tblTemporal(
id bigint AUTO_INCREMENT PRIMARY KEY,
idC bigint,
idVersion bigint) ENGINE = MEMORY;
INSERT into tblTemporal
SELECT null,
C.IdC,
CV.IdCVersion
FROM Cuentas as C join CuentasVersion as CV on C.IdCuenta = CV.IdCuenta
WHERE C.EstatusC=2
and CV.EstatusV=2
and CV.IdCVersion=(select MAX(IdCVersion) from ContratoVersion where IdContrato=C.IdContrato)
and CV.TipoPGenerar=2
and CV.TipoPExihibicion=1
and ((select DATE(Max(FechaCreo)) from Requisicion where IdContrato=C.IdContrato)<= DATE_ADD(CV.GeneradaPorPeriodo,INTERVAL NOW() DAY)
or (select DATE(Max(FechaCreo)) from Requisicion where IdContrato=C.IdContrato) is null);
When executing the previous script I get the following error:
1292 - Incorrect datetime value: '3'
What seems strange to me is that if I execute the select only it does not mark me any error and it brings the data correctly, I hope somebody can help me to know what I am doing wrong.