日期:2014-05-19  浏览次数:20545 次

请教两个字段合并成另一个新的字段问题!
比如:两个字段   c1   ,c2   生成c3
                              12     2           122
                              13     3           133  
                              14     4           144
                          现在就是想问如何c3的值,122,133,144如何生成,最好是在c3字段的默认值直接设置。请高手帮帮我。

------解决方案--------------------
select c1, c2, c3=rtrim(c1)+rtrim(c2)
from tbName

------解决方案--------------------
select c1, c2, c3=cast(c1 as varchar(50))+cast(c2 as varchar(50))
from
(
select c1=12, c2=2
union all
select 13,3
union all
select 14,4
)tmp


--result
c1 c2 c3
----------- ----------- ------------------------
12 2 122
13 3 133
14 4 144

(3 row(s) affected)


------解决方案--------------------
--用计算列吧,默认值估计做不到

create table T(c1 int, c2 int, c3 as rtrim(c1)+rtrim(c2))
insert T(c1, c2) select 12,2
insert T(c1, c2) select 13,3
insert T(c1, c2) select 14,4

select * from T

--result
c1 c2 c3
----------- ----------- ------------------------
12 2 122
13 3 133
14 4 144

(3 row(s) affected)