用pivot及存储过程
--------------------
创建临时表
CREATE table #yourtable ([Id] int, [Value] varchar(6), [ColumnName] varchar(13)) ; 插入数据 INSERT INTO #yourtable ([Id], [Value], [ColumnName]) VALUES (1, 'John', 'FirstName'), (2, '2.4', 'Amount'), (3, 'ZH1E4A', 'PostalCode'), (4, 'Fork', 'LastName'), (5, '857685', 'AccountNumber') ; --------------------
select Firstname, Amount, PostalCode, LastName, AccountNumber from ( select value, columnname from #yourtable ) d pivot ( max(value) for columnname in (Firstname, Amount, PostalCode, LastName, AccountNumber) ) piv;
posted on 2022-05-12 16:46  RogerLu  阅读(58)  评论(0编辑  收藏  举报