Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Columns

Author  Topic 

cutiebo2t
Constraint Violating Yak Guru

256 Posts

Posted - 2008-07-22 : 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)

17689 Posts

Posted - 2008-07-22 : 06:11:36
yes.
How do you want to merge it ?

concatenate ? select Level1a + Level1b + Levelc from yourtable


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

cutiebo2t
Constraint Violating Yak Guru

256 Posts

Posted - 2008-07-22 : 06:23:51
I want to combine them into 1 column
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-07-22 : 06:26:43
select coalesce(Level1a,'')+coalesce( Level1b,'') + coalesce(Levelc,'') from yourtable
Go to Top of Page

dexter.knudson
Constraint Violating Yak Guru

260 Posts

Posted - 2008-07-22 : 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.
Go to Top of Page

cutiebo2t
Constraint Violating Yak Guru

256 Posts

Posted - 2008-07-22 : 06:30:18
it doesn't combined into 1 column instead it merged in the same cell.
Go to Top of Page

cutiebo2t
Constraint Violating Yak Guru

256 Posts

Posted - 2008-07-22 : 06:38:35
any help?
Go to Top of Page

elancaster
A very urgent SQL Yakette

1208 Posts

Posted - 2008-07-22 : 06:46:03
how about some sample data to show us what you mean? guessing could take forever

Em
Go to Top of Page

cutiebo2t
Constraint Violating Yak Guru

256 Posts

Posted - 2008-07-22 : 06:47:16
Level1
a
b

Level2
c
d

Combined with new column
Level
a
b
c
d
Go to Top of Page

elancaster
A very urgent SQL Yakette

1208 Posts

Posted - 2008-07-22 : 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
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-07-22 : 06:54:06
What do you mean with "combined"?

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




E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

cutiebo2t
Constraint Violating Yak Guru

256 Posts

Posted - 2008-07-22 : 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
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-07-22 : 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
Go to Top of Page

cutiebo2t
Constraint Violating Yak Guru

256 Posts

Posted - 2008-07-22 : 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
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-07-22 : 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
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-07-22 : 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"
Go to Top of Page

cutiebo2t
Constraint Violating Yak Guru

256 Posts

Posted - 2008-07-22 : 07:06:17
I want level1 and level2 into 1 column and level3 and level4 into another column. Thanks
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-07-22 : 07:08:12
You still can't follow directions, can't you?


E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

cutiebo2t
Constraint Violating Yak Guru

256 Posts

Posted - 2008-07-22 : 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
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-07-22 : 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"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-07-22 : 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
Go to Top of Page
    Next Page

- Advertisement -