Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 2008
»
SQL Server 2008 - General
»
how to Pivot this
how to Pivot this
Rate Topic
Display Mode
Topic Options
Author
Message
yuvipoy
yuvipoy
Posted Wednesday, December 26, 2012 11:49 PM
SSC-Enthusiastic
Group: General Forum Members
Last Login: Today @ 2:53 AM
Points: 111,
Visits: 517
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
Post #1400479
robert.gerald.taylor
robert.gerald.taylor
Posted Thursday, December 27, 2012 6:40 AM
Right there with Babe
Group: General Forum Members
Last Login: Yesterday @ 1:48 PM
Points: 740,
Visits: 787
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
Post #1400599
vinu512
vinu512
Posted Friday, December 28, 2012 2:10 AM
Ten Centuries
Group: General Forum Members
Last Login: Monday, May 20, 2013 12:37 AM
Points: 1,049,
Visits: 1,439
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
Post #1400833
« Prev Topic
|
Next Topic »
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.