Ver Mensaje Individual
  #6 (permalink)  
Antiguo 13/07/2016, 11:25
solilopi
 
Fecha de Ingreso: enero-2012
Mensajes: 52
Antigüedad: 12 años, 2 meses
Puntos: 1
Pregunta Respuesta: Error en función MySql

hola gnzsoloyo, me ha parecido buena idea tu solución y la he adaptado a mi función con resultado idéntico: 0
Código MySQL:
Ver original
  1. CREATE DEFINER=`root`@`localhost` FUNCTION `dias_sin`() RETURNS smallint(6)
  2.  
  3. declare contador integer default 14;
  4. declare resultado smallint default 0;
  5.  
  6. SELECT MAX(salida_num)INTO ultimo FROM datos;
  7.  
  8.      
  9.      SELECT MAX(DATEDIFF((select fecha from datos where salida_num = contador),
  10.      (select fecha from datos where salida_num = contador + 1))) into dif FROM datos;
  11.      
  12.     if resultado < cast(dif as unsigned) then
  13.    
  14.         set resultado = cast(dif as unsigned);
  15.        
  16.     end if;
  17.    
  18.     set contador = contador+1;
  19.        
  20.     until contador = ultimo
  21.    
  22.     end repeat;
  23.    
  24. RETURN resultado;
  25.  
¿Cual es el error?, pues si hago:
Código MySQL:
Ver original
  1. SELECT MAX(DATEDIFF((select fecha from datos where salida_num = 25),
  2.      (select fecha from datos where salida_num = 24))) into dif FROM datos;
en una consulta normal a la Bd, sí lo hace bien. No lo entiendo!!!!

Última edición por gnzsoloyo; 13/07/2016 a las 11:30