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
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:
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 :
No comments:
Post a Comment