| Author |
Topic  |
|
cutiebo2t
Constraint Violating Yak Guru
256 Posts |
Posted - 07/22/2008 : 06:02:59
|
| I have 3 columns. Level1a Level1b Levelc. I want to merge them into 1 column. Is that possible? Thanks |
|
|
khtan
In (Som, Ni, Yak)
Singapore
16746 Posts |
Posted - 07/22/2008 : 06:11:36
|
yes. How do you want to merge it ?
concatenate ? select Level1a + Level1b + Levelc from yourtable
KH Time is always against us
|
 |
|
|
cutiebo2t
Constraint Violating Yak Guru
256 Posts |
Posted - 07/22/2008 : 06:23:51
|
| I want to combine them into 1 column |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
India
47099 Posts |
Posted - 07/22/2008 : 06:26:43
|
| select coalesce(Level1a,'')+coalesce( Level1b,'') + coalesce(Levelc,'') from yourtable |
 |
|
|
dexter.knudson
Constraint Violating Yak Guru
Australia
260 Posts |
Posted - 07/22/2008 : 06:28:33
|
update <tableName> set <newColumnName> = Level1a + ';' + Level1b + ';' + Levelc
You can leave out the + ';' if you don't want anything in between, or you could make it a blank space if you wish. This assumses that your colmns are strings. |
 |
|
|
cutiebo2t
Constraint Violating Yak Guru
256 Posts |
Posted - 07/22/2008 : 06:30:18
|
| it doesn't combined into 1 column instead it merged in the same cell. |
 |
|
|
cutiebo2t
Constraint Violating Yak Guru
256 Posts |
Posted - 07/22/2008 : 06:38:35
|
| any help? |
 |
|
|
elancaster
A very urgent SQL Yakette
United Kingdom
1208 Posts |
Posted - 07/22/2008 : 06:46:03
|
how about some sample data to show us what you mean? guessing could take forever
Em |
 |
|
|
cutiebo2t
Constraint Violating Yak Guru
256 Posts |
Posted - 07/22/2008 : 06:47:16
|
Level1 a b
Level2 c d
Combined with new column Level a b c d |
 |
|
|
elancaster
A very urgent SQL Yakette
United Kingdom
1208 Posts |
Posted - 07/22/2008 : 06:52:31
|
that just looks like a union? i.e.
select level1 from UrTable union all select level2 from UrTable
what about other columns? limiting the rows etc...?
Em |
Edited by - elancaster on 07/22/2008 06:52:54 |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
Sweden
29138 Posts |
|
|
cutiebo2t
Constraint Violating Yak Guru
256 Posts |
Posted - 07/22/2008 : 06:56:29
|
SELECT level1 FROM dbo.Comments_Scrub_Form UNION ALL SELECT level2 FROM dbo.Comments_Scrub_Form, SELECT level3 FROM dbo.Comments_Scrub_Form UNION ALL SELECT level4 FROM dbo.Comments_Scrub_Form
This is not working |
 |
|
|
madhivanan
Premature Yak Congratulator
India
22461 Posts |
Posted - 07/22/2008 : 07:02:42
|
quote: Originally posted by cutiebo2t
SELECT level1 FROM dbo.Comments_Scrub_Form UNION ALL SELECT level2 FROM dbo.Comments_Scrub_Form, SELECT level3 FROM dbo.Comments_Scrub_Form UNION ALL SELECT level4 FROM dbo.Comments_Scrub_Form
This is not working
It wont as you have unnecessary comma
Madhivanan
Failing to plan is Planning to fail |
 |
|
|
cutiebo2t
Constraint Violating Yak Guru
256 Posts |
Posted - 07/22/2008 : 07:03:27
|
I need to columns but it doesn't work:
SELECT level1 FROM dbo.Comments_Scrub_Form UNION ALL SELECT level2 FROM dbo.Comments_Scrub_Form SELECT level3 FROM dbo.Comments_Scrub_Form UNION ALL SELECT level4 FROM dbo.Comments_Scrub_Form |
 |
|
|
madhivanan
Premature Yak Congratulator
India
22461 Posts |
Posted - 07/22/2008 : 07:05:06
|
quote: Originally posted by cutiebo2t
I need to columns but it doesn't work:
SELECT level1 FROM dbo.Comments_Scrub_Form UNION ALL SELECT level2 FROM dbo.Comments_Scrub_Form SELECT level3 FROM dbo.Comments_Scrub_Form UNION ALL SELECT level4 FROM dbo.Comments_Scrub_Form
What do you mean by "it doesnt work"?
Madhivanan
Failing to plan is Planning to fail |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
Sweden
29138 Posts |
Posted - 07/22/2008 : 07:06:05
|
What is the problem now? Do you want us to continue guessing?!!?
Follow the links I posted earlier and give us a chance to help you.
quote: This is the link I have posted to you several times before. PLEASE READ and UNDERSTAND the concept and you will get help faster. http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx
It isn't that hard to follow the guidelines.
And here is another link for you, so that you will understand what WE face when YOU ask a question in your present manner. http://weblogs.sqlteam.com/jeffs/archive/2008/05/13/question-needed-not-answer.aspx
IF YOU DON'T FOLLOW THE GUIDELINES POSTED ABOVE, WE CAN'T HELP YOU BECUASE WE CAN'T READ YOU MIND.
E 12°55'05.25" N 56°04'39.16" |
Edited by - SwePeso on 07/22/2008 07:07:23 |
 |
|
|
cutiebo2t
Constraint Violating Yak Guru
256 Posts |
Posted - 07/22/2008 : 07:06:17
|
| I want level1 and level2 into 1 column and level3 and level4 into another column. Thanks |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
Sweden
29138 Posts |
Posted - 07/22/2008 : 07:08:12
|
You still can't follow directions, can't you?
E 12°55'05.25" N 56°04'39.16" |
 |
|
|
cutiebo2t
Constraint Violating Yak Guru
256 Posts |
Posted - 07/22/2008 : 07:09:59
|
Level1 a b
Level2 c d
Combined with new column Level a b c d
Another that neends to combined
Level3 e f
Level4 g h
Into new column e f g h
It's not working here:
SELECT level1 FROM dbo.Comments_Scrub_Form UNION ALL SELECT level2 FROM dbo.Comments_Scrub_Form AS test SELECT level3 FROM dbo.Comments_Scrub_Form UNION ALL SELECT level4 FROM dbo.Comments_Scrub_Form |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
Sweden
29138 Posts |
Posted - 07/22/2008 : 07:11:48
|
Please tell me why you are so reluctant to make things easier for us? Follow the guidelines in this topic http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx So that we know EXACTLY how the data looks like and how you want it presented.CREATE TABLE #Temp1
(
RowID INT IDENTITY(1, 1),
Col INT
)
CREATE TABLE #Temp2
(
RowID INT IDENTITY(1, 1),
Col INT
)
INSERT #Temp1
SELECT Level1 FROM dbo.Comments_Scrub_Form UNION
SELECT Level2 FROM dbo.Comments_Scrub_Form
ORDER BY 1
INSERT #Temp2
SELECT Level3 FROM dbo.Comments_Scrub_Form UNION
SELECT Level4 FROM dbo.Comments_Scrub_Form
-- Output
SELECT t1.Col,
t2.Col
FROM #Temp1 AS t1
FULL JOIN #Temp2 AS t2 ON t2.RowID = t1.RowID
E 12°55'05.25" N 56°04'39.16" |
Edited by - SwePeso on 07/22/2008 07:13:24 |
 |
|
|
madhivanan
Premature Yak Congratulator
India
22461 Posts |
Posted - 07/22/2008 : 07:13:09
|
Where do you want to show data? If you use front end application, show there
Madhivanan
Failing to plan is Planning to fail |
 |
|
Topic  |
|