SQL_UNPIVOT(行列转换)

--临时表

insert into ##table([column1],S1, S2,S3)
VALUES('VALUE','VALUE','VALUE','VALUE')

--把原S1, S2,S3列名 作为 star字段的内容,S1, S2,S3的数据放到qty字段中

insert into tableA([column1],[qty],[star])
select [column1],[qty],[star]
from ##table UNPIVOT(qty for star in (S1, S2,S3))

 

 

Colum1

S1

S2

S3

1

3

5

6

2

5

6

5

3

2

3

7

...

...

...

...

 

Colum1

Qty

star

1

3

S1

1

5

S2

1

6

S3

...

...

...

 

posted @ 2016-06-02 14:13  ETLeung  阅读(1006)  评论(0编辑  收藏  举报