SQL SERVER : Split comma separated string value - ASPMANTRA | Asp.Net,MVC,AngularJs,Jquery,Javascript,Sql Server AND WCF snippets and tutorial

SQL SERVER : Split comma separated string value


In this article I am going to explain how to split the comma separated string value in Sql Server.

Microsoft release the Sql Server 2016 in year 2016 and introduced new built-in table value function string_split. This function can be used to split a string value by a specified separator character and returns the result value inform of table. So we no need to write our user defined function to split the string value as we have doing earlier.


STRING_SPLIT function require two parameters:
First is string value
Second is separator

Another most important thing it requires database compatibility level to be at least 130.

SYNTAX
string_split(string , separator) 

Example :

In this example I am going to split the comma (,) separated string value.
declare @string varchar(150) ='asp.net,Sql server,MVC,Angular'select * from string_split(@string,',')

Result:

string_split




Example 2 :

In this example going to split the slash (/) separated string.
declare @string varchar(150) ='asp.net/Sql server/MVC/Angular'select * from string_split(@string,'/')

Result :

string_split



 

What do you think about this article?

If you found this article useful, please share and follow on Facebook, Twitter, Google Plus and other social media websites. To get free updates subscribe to newsletter. Please put your thoughts and feedback in comments section.


EmoticonEmoticon