Concatenate 2 columns from 2 tables into new column
-
Tuesday, November 27, 2012 7:37 AM
Hello,
i have 2 tables A and B and want to Concatenate the value in table A with value in table B to new column into table A or B?
there is no relation between the 2 table ?
need your support please
All Replies
-
Tuesday, November 27, 2012 7:56 AMThere must be one common key in both tables before you join them. If not, there is no meaning to do the join.
Many Thanks & Best Regards, Hua Min
-
Tuesday, November 27, 2012 8:02 AM
For this type of question, the recommendation is that you post:
1) CREATE TABLE statements for your tables.
2) INSERT statements with sample data.
3) The desired result given the sample data.
4) A short description of the business rules.
5) Which version of SQL Server you are using.
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se -
Tuesday, November 27, 2012 8:05 AMAnswerer
Please post sample data , if one table has more rows than the second one what would an output? SQL Server 2012 introduced CONCAT function for such purposes...
SELECT custid, city, region, country,
CONCAT(city, ', ' + region, ', ' + country) AS location
FROM Sales.Customers
WHERE custid > 85;Best Regards,Uri Dimant SQL Server MVP, http://sqlblog.com/blogs/uri_dimant/
MS SQL optimization: MS SQL Development and Optimization
MS SQL Blog: Large scale of database and data cleansing
MS SQL Consultants: Improves MS SQL Database Performance
-
Wednesday, November 28, 2012 11:21 AM
Thanks All, for your replies ,
i had to solve this by adding auto generated number for both table and join them to be able to run my statemant
- Marked As Answer by SQL Kitchen Wednesday, November 28, 2012 11:21 AM
-
Wednesday, November 28, 2012 11:56 AM
Hi
Based on same matching in both tables it is possible to concadinate the two column using inner join condition.Ex: select a.Col1+a.col2 from t1 a inner join t2 b on(t1.id=t2.id)
note:But here these both columns date type is must be same
Bset regrds
- Edited by perumasbala Wednesday, November 28, 2012 11:58 AM
-
Wednesday, November 28, 2012 12:34 PM
i had to solve this by adding auto generated number for both table and join them to be able to run my statemant
I hope your were able to apply the autonumber in a away that the join actually made sense and you did not just concatenate randomly paired rows.
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se -
Wednesday, November 28, 2012 1:09 PM
Hi,
WIthout having no relation how can you releated to tables ?
Is there any logic behind that ?
You need to do join between A and B .After that concate two attribute of A and B.
Using '+' .
Ahsan Kabir Please remember to click Mark as Answer and Vote as Helpful on posts that help you. This can be beneficial to other community members reading the thread. http://www.aktechforum.blogspot.com/
- Edited by Ahsan Kabir Wednesday, November 28, 2012 1:11 PM

