读书人

SQL列值修改,该怎么解决

发布时间: 2012-01-14 20:02:35 作者: rapoo

SQL列值修改
表aaaa
shapecode shapename
11 常温
12 低温
13 冰冻
变成
shapecode shapename
11 箱子(常温)
12 箱子(低温)
13 箱子(冰冻)
11 盒子(常温)
12 盒子(低温)
13 盒子(冰冻)

[解决办法]
create table tm(shapecode int ,shapename varchar(20))
insert into tm select 11,'常温'
insert into tm select 12,'低温'
insert into tm select 13,'冰冻'

select shapecode ,'箱子('+shapename +')' as shapename from tm
union
select shapecode ,'盒子('+shapename +')' as shapename from tm




[解决办法]

select t1.shapecode, t.col+'('+t1.shapename+')'
from
(select '盒子' as col
union all
select '箱子')t
cross join
aaaa t1
order by t.col,t1.shapecode asc

读书人网 >SQL Server

热点推荐