SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


how to Pivot this


how to Pivot this

Author
Message
yuvipoy
yuvipoy
Right there with Babe
Right there with Babe (786 reputation)Right there with Babe (786 reputation)Right there with Babe (786 reputation)Right there with Babe (786 reputation)Right there with Babe (786 reputation)Right there with Babe (786 reputation)Right there with Babe (786 reputation)Right there with Babe (786 reputation)

Group: General Forum Members
Points: 786 Visits: 1386
hi
i am having two tables one table is having header details and another is having data

Table_id Col_1 Col_2 Col_3 Col_4 Col_5 Col_6
1 Mytab_1_1 NULL Mytab_1_2 NULL Mytab_1_3 NULL


Ref_id Col_1 Col_2 Col_3 Col_4 Col_5 Col_6
1 1 NULL 2 NULL 3 NULL
1 9 NULL 8 NULL 4 NULL
1 4 NULL 5 NULL 6 NULL

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
robert.gerald.taylor
robert.gerald.taylor
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1791 Visits: 1484
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
vinu512
vinu512
SSCommitted
SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)

Group: General Forum Members
Points: 1685 Visits: 1625
yuvipoy (12/26/2012)
hi
i am having two tables one table is having header details and another is having data

Table_id Col_1 Col_2 Col_3 Col_4 Col_5 Col_6
1 Mytab_1_1 NULL Mytab_1_2 NULL Mytab_1_3 NULL


Ref_id Col_1 Col_2 Col_3 Col_4 Col_5 Col_6
1 1 NULL 2 NULL 3 NULL
1 9 NULL 8 NULL 4 NULL
1 4 NULL 5 NULL 6 NULL

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 ;-)
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search