SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Columns
 New Topic  Reply to Topic
 Printer Friendly
Next Page
Author Previous Topic Topic Next Topic
Page: of 2

cutiebo2t
Constraint Violating Yak Guru

256 Posts

Posted - 07/22/2008 :  06:02:59  Show Profile  Reply with Quote
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
17586 Posts

Posted - 07/22/2008 :  06:11:36  Show Profile  Reply with Quote
yes.
How do you want to merge it ?

concatenate ? select Level1a + Level1b + Levelc from yourtable


KH
Time is always against us

Go to Top of Page

cutiebo2t
Constraint Violating Yak Guru

256 Posts

Posted - 07/22/2008 :  06:23:51  Show Profile  Reply with Quote
I want to combine them into 1 column
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

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

dexter.knudson
Constraint Violating Yak Guru

Australia
260 Posts

Posted - 07/22/2008 :  06:28:33  Show Profile  Reply with Quote
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 - 07/22/2008 :  06:30:18  Show Profile  Reply with Quote
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 - 07/22/2008 :  06:38:35  Show Profile  Reply with Quote
any help?
Go to Top of Page

elancaster
A very urgent SQL Yakette

United Kingdom
1208 Posts

Posted - 07/22/2008 :  06:46:03  Show Profile  Reply with Quote
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 - 07/22/2008 :  06:47:16  Show Profile  Reply with Quote
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

United Kingdom
1208 Posts

Posted - 07/22/2008 :  06:52:31  Show Profile  Reply with Quote
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
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

Sweden
30114 Posts

Posted - 07/22/2008 :  06:54:06  Show Profile  Visit SwePeso's Homepage  Reply with Quote
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 - 07/22/2008 :  06:56:29  Show Profile  Reply with Quote
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

India
22744 Posts

Posted - 07/22/2008 :  07:02:42  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
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 - 07/22/2008 :  07:03:27  Show Profile  Reply with Quote
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

India
22744 Posts

Posted - 07/22/2008 :  07:05:06  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
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

Sweden
30114 Posts

Posted - 07/22/2008 :  07:06:05  Show Profile  Visit SwePeso's Homepage  Reply with Quote
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
Go to Top of Page

cutiebo2t
Constraint Violating Yak Guru

256 Posts

Posted - 07/22/2008 :  07:06:17  Show Profile  Reply with Quote
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

Sweden
30114 Posts

Posted - 07/22/2008 :  07:08:12  Show Profile  Visit SwePeso's Homepage  Reply with Quote
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 - 07/22/2008 :  07:09:59  Show Profile  Reply with Quote
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

Sweden
30114 Posts

Posted - 07/22/2008 :  07:11:48  Show Profile  Visit SwePeso's Homepage  Reply with Quote
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
Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22744 Posts

Posted - 07/22/2008 :  07:13:09  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
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
Page: of 2 Previous Topic Topic Next Topic  
Next Page
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.17 seconds. Powered By: Snitz Forums 2000