Separate line with delimiter # @ #
The next line I have to call three times using sql. Line: JAN # @ # PIET # @ # HENK
First call shoudl return: JAN Second call: PIET Third: HENK
So we could use # @ # as a separator, but it could be that the line: JAN # @ # PIET only. All three calls will be made where call 1 returns: JAN call 4 returns: PIET three returns: <>
The same can only happen for the JAN string.
Hope this explanation is enough for someone to help me in this case.
Thanks in advance.
Regards, Ryni
It looks to me like you are asking for a split function that maintains state like an enumerator. You really don't want that. This can be really bad.
I would recommend the string splitting function (in sql server they are called table functions). If you do this, in the worst case you will have to iterate over the result of the table. Anyway, you can find the function here: http://dpatrickcaldwell.blogspot.com/2008/08/table-valued-function-to-split-strings.html
Your usage would look like this:
SELECT *
FROM dbo.SplitString('JAN#@#PIET#@#HENK', '#@#')
-- PartId Part
-- ----------- --------
-- 1 JAN
-- 2 PIET
-- 3 HENK
SELECT *
FROM dbo.SplitString('JAN#@#PIET#@#HENK', '#@#')
WHERE PartId = 2
-- PartId Part
-- ----------- --------
-- 2 PIET
a source to share