1.11M Members

How to merge two columns ?

 
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
 
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

 
0
 

try this

SELECT Tel_H_Code + ' ' + Tel_H AS Tel_H
FROM Detailed_List
 
0
 

try this

SELECT Tel_H_Code + ' ' + Tel_H AS Tel_H
FROM Detailed_List

this command sums the values of fields!

 
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.

 
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
 
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 six months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article