How to co开发者_开发问答mbine two int columns into one.
My table1 is as follows:
name adress1 adress2
hhh 1 2
www 2 3
I want result as follows:
name columnz
hhh 12
www 23
In the upcoming SQL-server you can do:
SELECT name, concat(address1,address2) as columnz FROM table1
However SQL-server does not allow concat yet, so you'll have the use the '+' operator and a cast.
SELECT
name
,CAST(address1 AS char)+CAST(address2 AS char) as columnz
FROM table1
SQL is not that troublesome about the difference between strings and numbers.
Another option is:
SELECT name, (address1*10+address2) as columnz
FROM table1
SELECT name, CAST(ADRESS1 AS VARCHAR(20)) + CAST(ADRESS2 AS VARCHAR(20)) AS columnz from table1
Try this:
SELECT name, Concat(adress1, adress2) AS columnz FROM table1;
select name, convert(varchar, adress1) + convert(varchar, adress2) as columnz from table1;
精彩评论