Ver Mensaje Individual
  #2 (permalink)  
Antiguo 09/02/2011, 15:29
Avatar de Libras
Libras
Colaborador
 
Fecha de Ingreso: agosto-2006
Ubicación: En la hermosa perla de occidente
Mensajes: 7.412
Antigüedad: 17 años, 9 meses
Puntos: 774
Respuesta: Consulta con probabilidades

Un query dinamico te serviria?

Por ejemplo tienes en tu tabla los tipos de datos y quieres que si es int entonces te ordene por el campo nombre

Código SQL:
Ver original
  1. DECLARE @dato VARCHAR(200)
  2. DECLARE @query VARCHAR(MAX)
  3. DECLARE @orderby VARCHAR(200)
  4.  
  5. SELECT @dato=tipo_dato FROM tabla
  6. IF @dato='int'
  7.  SET @orderby='campo1'
  8. ELSE
  9.   SET @orderby='campo2'
  10.  
  11.   SET @query='select datos from tabla where dato=dato order by ' + @orderby
  12. EXEC Sp_sqlExec @query

Saludos!
__________________
What does an execution plan say to t-sql query? Go f**k yourself, if you are not happy with me