求救!!大哥们。。
表结构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