Ver Mensaje Individual
  #10 (permalink)  
Antiguo 29/11/2010, 14:21
Avatar de Snaft_J1
Snaft_J1
 
Fecha de Ingreso: diciembre-2006
Mensajes: 285
Antigüedad: 17 años, 5 meses
Puntos: 8
Respuesta: filtrado de tabla

hola, aqui te incluyo una muestra pequeña del sp que te sugiero hacer:
Código MySQL:
Ver original
  1. CREATE DEFINER=`root`@`localhost` PROCEDURE `demostracion`(prango varchar(10), punidad varchar(10))
  2.  
  3.   IF prango <> 'TODOS' THEN
  4.         SET @s = ' rango=' + prango;
  5.         SET @sw = true;
  6.   ELSEIF punidad <> 'TODOS' THEN
  7.         IF @sw = true THEN
  8.            SET @s = ' AND unidad=' + punidad;
  9.         ELSE
  10.            SET @s = ' unidad=' + punidad;
  11.         END IF;
  12.         SET @sw = true;
  13.   END IF;
  14.  
  15.   IF @sw = true THEN
  16.      SET @s = CONCAT('SELECT * FROM TU_TABLA WHERE ', @s);
  17.   ELSE
  18.      SET @s = 'SELECT * FROM TU_TABLA ';
  19.   END IF;
  20.  
  21.  
  22. PREPARE stmt FROM @s;
  23. EXECUTE stmt;

ahora al momento de llamar tu sp para probar lo podrias hacer con un:
Código SQL:
Ver original
  1. CALL demostracion ('TODOS', 'TODOS');

Espero te sirva y lo perfeccciones.
__________________
-= El conocimiento y el saber te hacen un ser libre =-
Ando en busca de conocimiento....