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 Newbies
»
combine column is same table
combine column is same table
Rate Topic
Display Mode
Topic Options
Author
Message
smmr_emon
smmr_emon
Posted Monday, December 03, 2012 3:53 PM
Forum Newbie
Group: General Forum Members
Last Login: Thursday, February 07, 2013 8:17 AM
Points: 1,
Visits: 5
hi,
i've 2 tables. table 1 is like
col1 col2 col3
x y z
in the other table the items(x, y, z) are like this
col1 col2 col3 col4 col5
x 1 <empty> 1 1
y <empty> 1 1 <empty>
z 1 1 1 1
i want to join the 2 tables and show the data in the following format
x 1,1,1
y 1,1
z 1,1,1,1
how can i do that? and is it possible to do in sql7?
sorry for bad formatting
thanx
Post #1392173
Sean Lange
Sean Lange
Posted Tuesday, December 04, 2012 7:56 AM
SSCrazy Eights
Group: General Forum Members
Last Login: Today @ 7:41 AM
Points: 8,622,
Visits: 8,263
Hi an welcome to SSC. It is impossible to provide any detailed help based on your post because there just aren't any details. I think that maybe what you want is called a cross tab. You can read about the technique by following the link in my signature. If that is not what you are looking for or you need specific help please read the link in my signature about best practices when posting questions. It will help guide you through how to make your post effective so you get assistance.
_______________________________________________________________
Need help? Help us help you.
Read the article at
http://www.sqlservercentral.com/articles/Best+Practices/61537/
for best practices on asking questions.
Need to split a string? Try Jeff Moden's
splitter
.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Post #1392505
tcv 11632
tcv 11632
Posted Tuesday, December 04, 2012 8:38 AM
Forum Newbie
Group: General Forum Members
Last Login: Thursday, February 21, 2013 4:18 AM
Points: 1,
Visits: 9
This is quite a bad situation, however perhaps this might help.... I am not sure it works (I haven't tested it), and it is a dirty solution, but perhaps it helps you on the way. Good luck!
SELECT TAB.COL
, ISNULL(COL2, ISNULL(COL3, ISNULL(COL4, COL5))) "COL2"
, CASE
WHEN COL2 IS NULL
THEN ISNULL(COL4, COL5)
ELSE ISNULL(COL3, ISNULL(COL4, COL5))
END "COL3"
, CASE
WHEN COL2 IS NULL
THEN COL5
WHEN COL3 IS NULL
THEN ISNULL(COL4, COL5)
ELSE COL4
END "COL4"
, CASE
WHEN COL2 IS NULL OR COL3 IS NULL OR COL4 IS NULL
THEN NULL,
ELSE COL5
END "COL5"
FROM TABLE2 T2
JOIN
(
SELECT COL1 "COL"
FROM TABLE1
UNION
SELECT COL2 "COL"
FROM TABLE1
UNION
SELECT COL3 "COL"
FROM TABLE1
) TAB
ON
T2.Col1=TAB.COL
Post #1392550
« 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.