how to Pivot this

  • hi

    i am having two tables one table is having header details and another is having data

    Table_idCol_1Col_2 Col_3Col_4 Col_5Col_6

    1Mytab_1_1NULL Mytab_1_2NULL Mytab_1_3 NULL

    Ref_idCol_1 Col_2Col_3 Col_4 Col_5Col_6

    11NULL 2NULL 3NULL

    19NULL 8NULL 4NULL

    14NULL 5NULL 6NULL

    i need to show to client as

    There will be similarity between table1 and table2 which is NULL value.

    Select Mytab_1_1,Mytab_1_2,Mytab_1_3 from table1 which will be header (i have ignored Null values)

    Select *from table2 which is having data

    my output will be something like

    Mytab_1_1,Mytab_1_2,Mytab_1_3 ---header

    1,2,3

    9,8,4

    4,5,6

    Thanks

  • From you're DDL, I can't see the FK relationship, so I'm not sure how you're joining your two tables. After you've done that, you can take a look at this: http://www.kodyaz.com/articles/t-sql-pivot-tables-in-sql-server-tutorial-with-examples.aspx for Pivot examples.

    HTH,

    Rob

  • yuvipoy (12/26/2012)


    hi

    i am having two tables one table is having header details and another is having data

    Table_idCol_1Col_2 Col_3Col_4 Col_5Col_6

    1Mytab_1_1NULL Mytab_1_2NULL Mytab_1_3 NULL

    Ref_idCol_1 Col_2Col_3 Col_4 Col_5Col_6

    11NULL 2NULL 3NULL

    19NULL 8NULL 4NULL

    14NULL 5NULL 6NULL

    i need to show to client as

    There will be similarity between table1 and table2 which is NULL value.

    Select Mytab_1_1,Mytab_1_2,Mytab_1_3 from table1 which will be header (i have ignored Null values)

    Select *from table2 which is having data

    my output will be something like

    Mytab_1_1,Mytab_1_2,Mytab_1_3 ---header

    1,2,3

    9,8,4

    4,5,6

    Thanks

    With the incomplete/inefficient sample data you have provided, I have a solution which is really easy.....this is how it goes:

    Select Col_1 As MyTab_1, Col_2 As MyTab_2, Col_3 As MyTab_3 From <TableName>

    Please post full information about the requirement, DDL, Sample Data as shown in the link in my signature and you might get a better solution.

    Vinu Vijayan

    For better and faster solutions please check..."How to post data/code on a forum to get the best help" - Jeff Moden[/url] 😉

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

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