Ver Mensaje Individual
  #4 (permalink)  
Antiguo 13/03/2014, 16:43
Avatar de Libras
Libras
Colaborador
 
Fecha de Ingreso: agosto-2006
Ubicación: En la hermosa perla de occidente
Mensajes: 7.412
Antigüedad: 18 años, 3 meses
Puntos: 774
Respuesta: Ordenamiento Ascendente de codigo

Código SQL:
Ver original
  1. IF OBJECT_ID('tempdb..#temp') IS NOT NULL DROP TABLE #temp
  2. IF OBJECT_ID('tempdb..#ordenada') IS NOT NULL DROP TABLE #ordenada
  3.  
  4. CREATE TABLE #temp
  5. (
  6. valor VARCHAR(20)
  7. )
  8.  
  9.  
  10. INSERT INTO #temp VALUES ('4')
  11. INSERT INTO #temp VALUES ('2')
  12. INSERT INTO #temp VALUES ('3')
  13. INSERT INTO #temp VALUES ('1')
  14. INSERT INTO #temp VALUES ('A1')
  15. INSERT INTO #temp VALUES ('A2')
  16. INSERT INTO #temp VALUES ('5')
  17. INSERT INTO #temp VALUES ('6')
  18. INSERT INTO #temp VALUES ('A3')
  19. INSERT INTO #temp VALUES ('B1')
  20. INSERT INTO #temp VALUES ('7')
  21. INSERT INTO #temp VALUES ('10')
  22. INSERT INTO #temp VALUES ('100')
  23. INSERT INTO #temp VALUES ('20')
  24. INSERT INTO #temp VALUES ('ABC10')
  25. INSERT INTO #temp VALUES ('ABC01')
  26.  
  27. DROP TABLE #ordenada
  28.  
  29. CREATE TABLE #ordenada
  30. (
  31. orden INT IDENTITY(1,1),
  32. campo VARCHAR(20)
  33. )
  34.  
  35.  
  36.  
  37. INSERT INTO #ordenada
  38. SELECT * FROM(
  39. SELECT CASE WHEN isnumeric(valor)=1 THEN CONVERT(INT,valor) END campo FROM #temp
  40. ) AS t1 WHERE campo IS NOT NULL
  41. ORDER BY campo ASC
  42.  
  43.  
  44. INSERT INTO #ordenada
  45. SELECT * FROM(
  46. SELECT CASE WHEN isnumeric(valor)=0 THEN valor END campo FROM #temp
  47. ) AS t1 WHERE campo IS NOT NULL
  48.  
  49. SELECT campo FROM #ordenada

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