开发者

how to combine two numeric fields?

开发者 https://www.devze.com 2023-04-11 02:10 出处:网络
How to co开发者_开发问答mbine two int columns into one. My table1 is as follows: nameadress1adress2

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;

0

精彩评论

暂无评论...
验证码 换一张
取 消