1,105,578 Community Members

How to merge two columns ?

Member Avatar
cVz
Junior Poster
139 posts since Mar 2008
Reputation Points: 19 [?]
Q&As Helped to Solve: 7 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi , I have 2 columns named

1. Tel_H
2. Tel_H_Code

How can i merge these two columns to make them one ??

I am clueless here...The best i can do is to view them as one

SELECT Tel_H_Code + Tel_H AS 'Tel_H'
FROM Detailed_List
Member Avatar
emircan1986
Newbie Poster
1 post since Apr 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

maybe you can use select into statement, with it you merge two colums and take it another table like that

SELECT Tel_H_Code + Tel_H AS 'Tel_H' into Table1
FROM Detailed_List

so you can use it
select Tel_H from Table1

Member Avatar
sierrainfo
Junior Poster
144 posts since May 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 9 [?]
Skill Endorsements: 0 [?]
 
0
 

try this

SELECT Tel_H_Code + ' ' + Tel_H AS Tel_H
FROM Detailed_List
Member Avatar
chatbaz
Newbie Poster
2 posts since Dec 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

try this

SELECT Tel_H_Code + ' ' + Tel_H AS Tel_H
FROM Detailed_List

this command sums the values of fields!

Member Avatar
adam_k
Veteran Poster
1,056 posts since Jun 2011
Reputation Points: 239 [?]
Q&As Helped to Solve: 212 [?]
Skill Endorsements: 17 [?]
 
0
 

Let me start by saying that you have ressurected a 3 year old topic. You should have read the warning and let it be. Especially when you don't really know what you are talking about.

The plus symbol (+) has 2 functions:
a) to add when used with numbers
b) to concatenate when used with strings.

The post that you've commented includes a space within quotes, so at best it will produce an error if the Tel_H_Code or Tel_H is a number. If they have been declared as chars then it will just concatenate them.

Member Avatar
chatbaz
Newbie Poster
2 posts since Dec 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

yes you're right, it's an old topic but many people read this topic that doesn't have a true result.

I tried this command for two numeric fields and it summed them definitely! so the space within quotes didn't work!

the solution is:

Select COALESCE (CAST(Tel_H AS varchar), '') + ' - ' + COALESCE (CAST(Tel_H AS varchar), '') AS Concatenation
from Detailed_List
Member Avatar
Todster
Newbie Poster
1 post since Feb 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

This worked to combine 2 string values (first name & last name) from 2 separate columns (first_name, last_name) into 1 new column (full_name). Straight out of the textbook: SQL Fundamentals 3rd edition pg. 344:

select employee_id, first_name || ' ' || last_name AS full_name, hire_date
from l_employees;

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article