如何连接不同表中的两个或更多列 [英] how to concat two or more column from different tables

查看:81
本文介绍了如何连接不同表中的两个或更多列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,
我想合并列值并将其与不同的表存储到单独的表中.您可以引导或发送任何摘要吗?

hello,
i want to concat column values and stored into separate table from diifernt tables.can u guide or send any snippets

推荐答案

并不十分困难

Not terribly difficult

DECLARE @value1 NVARCHAR
DECLARE @value2 NVARCHAR

SELECT @value1 = column FROM table1 WHERE ...
SELECT @value2 = column FROM table2 WHERE ...

INSERT INTO table3(columns) VALUES(@value1 + @value2)


Are谈论String Concatination吗?
Are talking about String Concatination ?


在那里...
这两个表中是否有任何公共列,如果有的话,这是可能的.
首先,您可以使用join从两个表中获取列,然后将它们插入到temp表中;现在,您可以从temp表中将两个列合并为一个列值.


插入到#ConCatTable(col1_tab1,col2_tab2)
从table1 t1选择SELECT t1.col1_tab1,t2.col2_tab2加入table2 t2
ONt1.common_colm = t2.comon_colm


从#ConCatTable中选择RTRIM(col1_tab1)+''_''+ LTRIM(col1_tab2)
hi there...
is there is any common column in both table, if it is there then it is possible.
first u take columns from both table using join and insert into temp table, and now from temp table u can concat two columns in one column value.


INSERT INTO #ConCatTable(col1_tab1,col2_tab2)
SELECT t1.col1_tab1,t2.col2_tab2 FROM table1 t1 join table2 t2
ONt1.common_colm = t2.comon_colm


SELECT RTRIM(col1_tab1)+''_''+LTRIM(col1_tab2) FROM #ConCatTable


这篇关于如何连接不同表中的两个或更多列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆