首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

求救!大哥们。该如何处理

2012-03-03 
求救!!大哥们。。表结构table1idabcd120212325...要插到临时表中。变成#tempidtypevalues1a201b211c231d25...

求救!!大哥们。。
表结构table1
id     a     b       c         d
1     20     21     23       25
...

要插到临时表中。
变成   #temp
id     type     values
1         a             20
1         b             21
1         c             23
1         d             25
...
求大家帮忙。。谢谢!!

[解决办法]
create #temp(id int,type varchar(10),values int)

insert #temp
select id, 'a ' as type,a as values from table1 union all
select id, 'b ' as type,b as values from table1 union all
select id, 'c ' as type,c as values from table1 union all
select id, 'd ' as type,d as values from table1
[解决办法]
列應該是固定的吧
Select * Into #temp
From
(
Select id, 'a ' As type, a As [values] From table1
Union All
Select id, 'b ' As type, b As [values] From table1
Union All
Select id, 'c ' As type, c As [values] From table1
Union All
Select id, 'd ' As type, d As [values] From table1) A

热点排行