Help to read the records and insert in another table

  • Hi,

      I would like to read the records in one table and insert in into another table using some stored procedure in efficient way.

    Table-1 has the data like

    Name     column1     column2    column3

    x              1              2            3

    y              4              5            6

    z              7              8             9

    This data needs to be inserted in another table like

    x           column1     1

    x           column2      2

    x           column3       3

    y           column1       4

    etc.,

    Thanks

     

     

  • SELECT Name, 'column1' AS newColumnName, column1 AS newColumnValue

    FROM yourtable

    UNION ALL

    SELECT Name, 'column2', column2

    FROM yourtable

    UNION ALL

    SELECT Name, 'column3', column3

    FROM yourtable

  • Hi,

      Thanks for your reply.But i have hundreds of rows and columns which i don't want to specify in the query.I am trying to achieve this using some stored procedure.

    Thanks

    Rajee

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply