T-SQL:如何将逗号分隔值从列拆分为行?

发布于 2024-08-08 08:56:57 字数 567 浏览 3 评论 0原文

我有下表(引用的数量是可变的):

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦开始←不甜 2024-08-15 08:56:57

您使用的是哪个 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文