Is there a function in SQL Server 2008 or higher to return the Nth element of a delimited string? For example, let's say that I have a string like 'apple|orange|banana' and I want to get the 2nd element in this string which is 'orange'. Is there any built-in function to do this - something like GetElement('apple|orange|banana',2,'|') where you could pass the delimited string, the element number, and the delimiter? If not, then could someone please show me the code to do this programmatically?
Thanks very much!