1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to insert data from table and pivot it

Discussion in 'Programming/Internet' started by TigSh, Sep 12, 2018.

  1. TigSh

    TigSh Guest

    I have 2 tables.

    Table1 has around 2k columns which looks like:

    Id A B C D E F G H...........................................AA
    1
    2


    Table2 has 2 columns which looks like:

    Id Category
    1 A
    1 C
    1 AA
    2 B
    2 D


    I want to insert and pivot the data of table2 in table1

    Table 1 should finally look like

    Id A B C D E F G H...........................................AA
    1 1 0 1 0 0 0 0 0...........................................0
    2 0 1 1 0 0 0 0 0...........................................0


    I am not sure how to do this in sql. Would really appreciate any help on this.

    Login To add answer/comment
     

Share This Page