将SQL表行动态转换为列 [英] Pivot table SQL rows to columns dynamically
本文介绍了将SQL表行动态转换为列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问候,
我有一张桌子如下:
Regards,
I have a table as below:
create table #t (
Factura varchar(15),
ReciboCaja varchar(15),
ReciboCajaValor varchar(15),
)
insert into #t values('1', '1', '1')
insert into #t values('1', '2', '2')
insert into #t values('1', '3', '3')
insert into #t values('2', '4', '1')
insert into #t values('2', '5', '1')
insert into #t values('3', '6', '1')
insert into #t values('3', '7', '1')
insert into #t values('3', '8', '1')
我需要通过动态支点向我提供以下结果
I need that through a dynamic pivot deliver me the following result
Factura ReciboCaja1 ReciboValor1 ReciboCaja2 ReciboValor2 ReciboCaja3 ReciboValor3
1 1 1 2 2 3 3
2 4 1 5 1 null null
3 6 1 7 1 8 1
提前致谢。
将西班牙文改为英文文本(使用谷歌翻译)[/编辑]
Thanks in advance.
Changed Spanish text into English text (using Google Translate)[/Edit]
推荐答案
阅读我的文章此处 [ ^ ]
有解释,样本等。
read my article here[^] on CodeProject.
Has explanation, samples etc.
这篇关于将SQL表行动态转换为列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文