T-SQL Split string into many-to-one relationship?

独自空忆成欢 提交于 2019-12-03 20:55:24
Arvo

In SQL2000 you need cursors. In SQL2005/2008, you can use CROSS APPLY satement; probably like next (can't test just now):

SELECT T.ID, S.Item AS dataItem
FROM @temp AS T CROSS APPLY dbo.__StringSplit(T.data, ',', T.ID) AS S

EDIT - I found this page on CROSS APPLY and then came up with:

SELECT T.ID, S.Item AS dataItem
FROM @temp AS T
    CROSS APPLY
    dbo.__StringSplit(T.data, ',', T.ID) AS S
WHERE T.ID = S.RefID

Which solved my problem :-)

your split string function is really slow, here is a link to make a much faster one:

http://www.sommarskog.se/arrays-in-sql.html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!