Ver Mensaje Individual
  #4 (permalink)  
Antiguo 08/11/2012, 15:57
jisravila
 
Fecha de Ingreso: noviembre-2009
Mensajes: 110
Antigüedad: 14 años, 5 meses
Puntos: 1
Respuesta: Ordenar por campo y tipo de orden recibidos en Procedimiento Almacenado

Muchas gracias por sus respuestas, les comento como me fue:

Probe con esto:

Código SQL:
Ver original
  1. SET @campo = 'municipio';
  2. SET @orden = 'ASC';
  3. SET @s = CONCAT('SELECT * FROM municipio ORDER BY ',@campo,' ',@orden);
  4. PREPARE stmt2 FROM @s;
  5. EXECUTE stmt2;
  6. DEALLOCATE PREPARE stmt2;

y me arroja el siguiente error

>[Error] Líneas de script: 4-9 ----------------------
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SET @orden = 'ASC';
SET @s = CONCAT('SELECT * FROM municipio ORDER BY ',@campo,'' at line 2


y estas advertencias

Advertencias: --->
W (1): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SET @orden = 'ASC';
SET @s = CONCAT('SELECT * FROM municipio ORDER BY ',@campo,'' at line 2