T-SQL:如何将逗号分隔值从列拆分为行?
我有下表(引用的数量是可变的):
Id | FK_ID| Reference |
-----------------------
1 2100 GI2, GI32
2 2344 GI56
我需要以下结果:
Id | FK_ID| Reference |
-----------------------
1 2100 GI2
2 2100 GI32
3 2344 GI56
是否有任何简短的方法可以使用 MS SQL Server 2005 来转换这样的数据?
谢谢
编辑:直接链接到解决方案: http ://www.sommarskog.se/arrays-in-sql-2005.html#iter-list-of-strings
I have the following table (the number of the references is variable):
Id | FK_ID| Reference |
-----------------------
1 2100 GI2, GI32
2 2344 GI56
And I need the following result:
Id | FK_ID| Reference |
-----------------------
1 2100 GI2
2 2100 GI32
3 2344 GI56
Is there any short way to transform the data like this using MS SQL Server 2005?
Thank you
EDIT: Direct link to the solution:
http://www.sommarskog.se/arrays-in-sql-2005.html#iter-list-of-strings
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请参阅:
Please see:
您使用的是哪个 SQL Server 版本?
2005 年之前
使用实用程序 Numbers 表,如此处.
我之前已经使用过很多次并且非常成功。
2005 年及之后
阅读开发人员 Mitch Wheat 的回答。
Which SQL Server version are you using?
Prior 2005
Use utility Numbers table as explained here.
I've used it many times before with great success.
2005 and after
Read fellow developer Mitch Wheat's answer.