So I have a dataset that looks roughly like this:
01/02/2022, "bananas, apples and oranges", "accepted", "John"
01/05/2022, "bananas and grapes", "accepted", "Mary"
01/08/2022, "kale and bananas", "rejected", "John"
I need to transform it into:
01/02/2022, "bananas", "accepted", "John"
01/02/2022, "apples", "accepted", "John"
01/02/2022, "oranges", "accepted", "John"
01/05/2022, "bananas, "accepted", "Mary"
etc.
My problem is extracting the substrings for the types of fruit. The pattern is reliable in that the last delimiter is always " and ", and if there is another one before it, it's always ", ". So I can use CHARINDEX to find the position of the start of each word. But I struggle with finding the position of the end of the word. I could probably do it with a ton of CASE WHENs but is there an easier way?
(I asked this question earlier but I did a bad job of describing the problem then.)