Tengo el siguiente problema.
Tengo la siguiente tabla llamada recorrido vehiculo
Código:
Tengo un procedimiento almacenado con la siguiente estructuraID_RECORRIDO_VEHICULO ID_VEHICULO LONGITUD LATITUD TAG FECHA HORA KILOMETROS_RECORRIDOS ------------------------ -------------- ------------ ---------- ------ --------- ----------- ------------------------ 2 2 -102.6437942 22.7683047 tag1 2009/04/07 08:05:00 AM 0 3 2 -102.6297142 22.7723965 tag1 2009/04/07 08:10:00 AM 0 4 2 -102.6222349 22.774792 tag1 2009/04/07 08:15:00 AM 0 5 2 -102.6135026 22.7754072 tag1 2009/04/07 08:20:00 AM 0 6 1 -102.6067245 22.7747583 tag1 2009/04/09 08:25:00 AM 0 7 1 -102.5945086 22.7734048 tag1 2009/04/09 08:30:00 AM 0 8 1 -102.585904 22.7739324 tag1 2009/04/09 08:35:00 AM 0
Código:
Es un procedimiento en el que le paso un paramentro de tipo Date, para hacer una consulta por medio de ese campo en un cursor, y en base a ese resultado, pues inserto datos en otra tabla llamada tmp.drop procedure IF EXISTS insertDistance; go CREATE PROCEDURE insertDistance(IN fecha date) BEGIN DECLARE done INT DEFAULT 0; DECLARE id INTEGER; DECLARE lat double; DECLARE lng double; DECLARE curPuntos CURSOR FOR SELECT ID_RECORRIDO_VEHICULO,LATITUD,LONGITUD FROM recorrido_vehiculo where FECHA=fecha; DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1; OPEN curPuntos; REPEAT FETCH curPuntos INTO id,lat,lng; IF NOT done THEN insert into tmp (ID,LATITUD,LONGITUD,FECHA) values (id,lat,lng,fecha); END IF; UNTIL done END REPEAT; CLOSE curPuntos; END
El problema es que no me respeta el select del cursor.
Mando llamar el procedimiento de esta forma:
Código:
Segun mi tabla de datos, me deberia de filtrar solo 4 resgistros y me los filtra todos.call insertDistance('2009-04-07')
La pregunta es, esta mal el select
Código:
Con un tipo de datos int o varchar si funciona.Por ejemplo esto si funciona:DECLARE curPuntos CURSOR FOR SELECT ID_RECORRIDO_VEHICULO,LATITUD,LONGITUD FROM recorrido_vehiculo where FECHA=fecha;
Código:
Espero que alguien me pueda ayudar, ya perdi mucho tiempo c on este problema.DECLARE curPuntos CURSOR FOR SELECT ID_RECORRIDO_VEHICULO,LATITUD,LONGITUD FROM recorrido_vehiculo where id_recorrido_vehiculo=2;
Saludos