调换表格
你好,我想旋转一个完整的桌子:
LANGUAGE litAccept litDelete litErrorMsg ..............
-------------------------------------------------
SPANISH Accept Delete Error has ocurred
ENGLISH Aceptar Borrar Ha ocurrido un error
.....
变成这样的东西:
LANGUAGE ENGLISH SPANISH
---------------------------------------
litAccept Accept Aceptar
litDelete Aceptar Borrar
litErrorMsg Error.. Ha ocurridO..
...
我看到用 PIVOT 你可以旋转桌子,但我不知道是谁做的!
请帮忙,谢谢
Hi I would like to rotate a full table:
LANGUAGE litAccept litDelete litErrorMsg ..............
-------------------------------------------------
SPANISH Accept Delete Error has ocurred
ENGLISH Aceptar Borrar Ha ocurrido un error
.....
into something like this:
LANGUAGE ENGLISH SPANISH
---------------------------------------
litAccept Accept Aceptar
litDelete Aceptar Borrar
litErrorMsg Error.. Ha ocurridO..
...
I see with PIVOT you can rotate a table, but I don't know who do this!
Please help, thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
http://www.simple- talk.com/community/blogs/andras/archive/2007/09/14/37265.aspx
Pivot 无法执行“动态”操作,因此您必须使用此方法
http://www.simple-talk.com/community/blogs/andras/archive/2007/09/14/37265.aspx
Pivot can't do 'dynamic' so you'll have to use this method
哇我已经做到了!!
现在我明白了 PIVOT 是如何工作的。我尝试使用动态 SQL 一次旋转整个表,但没有办法将其适应pivot 的语法。旋转必须逐列 (PIVOT) 或逐行 (UNPIVOT) 完成,将它们插入临时表中以在最后获得完整的转置。
我认为这就是我的方法..但也许它可以在单个查询中完成? (UNION ALL ins 无效,你知道;P)
第二天我会写下我找到的解决方案。
谢谢!
Wow I have done it!!
Now I understand how it works PIVOT. I tried to rotate the entire table at once with dynamic SQL and there is no way to fit it in the syntax of pivot. The rotation must be done column by column (PIVOT) or line by line (UNPIVOT) inserting them in a temporally table to get the full transposing at the end.
I think this is the way for me.. but maybe it can be done in single query?? (UNION ALL ins't valid, you know ;P)
Next day I will write the solution I found.
Thanks!
这可以使用动态 SQL 结合
UNPIVOT
和PIVOT
来完成。请参阅SQL Fiddle 演示
This can be completed using Dynamic SQL with both an
UNPIVOT
and then aPIVOT
.See SQL Fiddle with a Demo