Ver Mensaje Individual
  #15 (permalink)  
Antiguo 22/09/2011, 10:02
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, 8 meses
Puntos: 774
Respuesta: Query cruzada

Probe esta funcion en sql express 2005:

Código SQL:
Ver original
  1. --Create the table and insert values as portrayed in the previous example.
  2. DROP TABLE #pvt
  3. CREATE TABLE #pvt (VendorID INT, Emp1 INT, Emp2 INT,
  4.     Emp3 INT, Emp4 INT, Emp5 INT);
  5. GO
  6. INSERT INTO #pvt VALUES (1,4,3,5,4,4);
  7. INSERT INTO #pvt VALUES (2,4,1,5,5,5);
  8. INSERT INTO #pvt VALUES (3,4,3,5,4,4);
  9. INSERT INTO #pvt VALUES (4,4,2,5,5,4);
  10. INSERT INTO #pvt VALUES (5,5,1,5,5,5);
  11. GO
  12. --Unpivot the table.
  13. SELECT VendorID, Employee, Orders
  14. FROM
  15.    (SELECT VendorID, Emp1, Emp2, Emp3, Emp4, Emp5
  16.    FROM #pvt) p
  17. UNPIVOT
  18.    (Orders FOR Employee IN
  19.       (Emp1, Emp2, Emp3, Emp4, Emp5)
  20. )AS unpvt;

Y si funciona, a ver un ejemplo de tus datos para ayudarte
__________________
What does an execution plan say to t-sql query? Go f**k yourself, if you are not happy with me