you will use XML function or might be different custom functions.
Let me explain this with below example. Suppose you have a string like below
DECLARE @FriendList AS VARCHAR(1000)
SET @FriendList ='Ravi,Suyash,Vaibhav,Shyam,Pankaj,Rajul,Javed'
Now you want output like below
Then in such cases, you will follow 2 approaches (their might be other as well)
Approach 1:- Write a function like below and use it.
And once this function is created you can use like below
Approach 2 :- You can use XML option in SQL SERVER as shown in below
So, the good news is now in SQL SERVER 2016 you don’t need to write so many lines to split any string. In SQL SERVER 2016 a new string function is Introduced which is
STRING_SPLIT
The use of this function is very easy and below is the syntax
STRING_SPLIT (string, separator)
Now, let me show you same output using STRING_SPLIT function
Isn’t it easy ?
I hope you will like this easy way to split the string.
Provide your feedback.
RJ !!!