pseudocode for a max of five members - may need adjusting
SELECT
case firstComma
when none then
left(str, firstTild - 1) + ',' + substring(str, firstTild + 1, secondTild - firstTild)
else
case secondComma
when none then ----------------two members
left(str, firstTild - 1) + ',' + substring(str, firstTild + 1, secondTild - firstTild-1) + '/' + substring(str, firstComma + 1, charIndex('~',str, firstComma) - firstComma-1) + ',' + substring(str, charIndex('~',str, firstComma)+1, charIndex('~',str,charIndex('~',str, firstComma)+1)
else
case thirdComma
when none then -------three members
left(str, firstTild - 1) + ',' + substring(str, firstTild + 1, secondTild - firstTild-1) + '/' + substring(str, firstComma + 1, charIndex('~',str, firstComma) - firstComma-1) + ',' + substring(str, charIndex('~',str, firstComma)+1, charIndex('~',str,charIndex('~',str, firstComma)+1) + '/' + substring(str, secondComma + 1, charIndex('~',str, secondComma) - secondComma-1) + ',' + substring(str, charIndex('~',str, secondComma)+1, charIndex('~',str,charIndex('~',str, secondComma)+1)
else
case fourthComma
when none then ----four members
left(str, firstTild - 1) + ',' + substring(str, firstTild + 1, secondTild - firstTild-1) + '/' + substring(str, firstComma + 1, charIndex('~',str, firstComma) - firstComma-1) + ',' + substring(str, charIndex('~',str, firstComma)+1, charIndex('~',str,charIndex('~',str, firstComma)+1) + '/' + substring(str, secondComma + 1, charIndex('~',str, secondComma) - secondComma-1) + ',' + substring(str, charIndex('~',str, secondComma)+1, charIndex('~',str,charIndex('~',str, secondComma)+1) + '/' + substring(str, thirdComma + 1, charIndex('~',str, thirdComma) - thirdComma-1) + ',' + substring(str, charIndex('~',str, thirdComma)+1, charIndex('~',str,charIndex('~',str, thirdComma)+1)
else
left(str, firstTild - 1) + ',' + substring(str, firstTild + 1, secondTild - firstTild-1) + '/' + substring(str, firstComma + 1, charIndex('~',str, firstComma) - firstComma-1) + ',' + substring(str, charIndex('~',str, firstComma)+1, charIndex('~',str,charIndex('~',str, firstComma)+1) + '/' + substring(str, secondComma + 1, charIndex('~',str, secondComma) - secondComma-1) + ',' + substring(str, charIndex('~',str, secondComma)+1, charIndex('~',str,charIndex('~',str, secondComma)+1) + '/' + substring(str, thirdComma + 1, charIndex('~',str, thirdComma) - thirdComma-1) + ',' + substring(str, charIndex('~',str, thirdComma)+1, charIndex('~',str,charIndex('~',str, thirdComma)+1) + '/' + substring(str, fourthComma + 1, charIndex('~',str, fourthComma) - fourthComma-1) + ',' + substring(str, charIndex('~',str, fourthComma)+1, charIndex('~',str,charIndex('~',str, fourthComma)+1)
end
end
end
end
FROM myTable
Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)