Home Forums SQL Server 2005 T-SQL (SS2K5) inserting horizontal records from table1 as vertical records in table2 RE: inserting horizontal records from table1 as vertical records in table2

  • INSERT INTO table2(frmdt,todt)

    SELECT ca.frmdt,ca.todt

    FROM table1 t

    CROSS APPLY(SELECT FDT1, TODT1

    UNION ALL

    SELECT FDT2, TODT2

    UNION ALL

    SELECT FDT3, TODT3) ca(frmdt,todt)

    ____________________________________________________

    Deja View - The strange feeling that somewhere, sometime you've optimised this query before

    How to get the best help on a forum

    http://www.sqlservercentral.com/articles/Best+Practices/61537