如何将两个int列合并为一个。
My table1 is as follows:
name adress1 adress2
hhh 1 2
www 2 3
我想要的结果如下:
name columnz
hhh 12
www 23
答案 0 :(得分:2)
在即将推出的SQL服务器中,你可以这样做:
<击> 撞击>
<击> 击><击>
SELECT name,concat(address1,address2)as columnz FROM table1 击>
然而,SQL-server还不允许使用concat,因此您将使用'+'运算符和强制转换。
SELECT
name
,CAST(address1 AS char)+CAST(address2 AS char) as columnz
FROM table1
SQL对字符串和数字之间的差异并不那么麻烦。
另一种选择是:
SELECT name, (address1*10+address2) as columnz
FROM table1
答案 1 :(得分:1)
试试这个:
SELECT name, Concat(adress1, adress2) AS columnz FROM table1;
答案 2 :(得分:1)
SELECT name, CAST(ADRESS1 AS VARCHAR(20)) + CAST(ADRESS2 AS VARCHAR(20)) AS columnz from table1
答案 3 :(得分:0)
select name, convert(varchar, adress1) + convert(varchar, adress2) as columnz from table1;