27,580
社区成员
发帖
与我相关
我的任务
分享
select 字段1,字段2,字段1+字段2 字段3
from 表
如果字段2是数字类型的
select 字段1,字段2,字段1+cast(字段2,char(2)) 字段3
from 表
select 字段1,字段2,字段+字段 字段3
from 表
--> 测试数据: #T
if object_id('tempdb.dbo.#T') is not null drop table #T
create table #T (字段1 varchar(11),字段2 int)
insert into #T
select 'a',1 union all
select 'b',2 union all
select 'c',3
go
-->用计算列:
alter table #T add 字段3 as 字段1+ltrim(字段2)
go
select * from #T
/*
字段1 字段2 字段3
----------- ----------- -----------------------
a 1 a1
b 2 b2
c 3 c3
*/