Quantcast
Channel: CodeSection,代码区,SQL Server(mssql)数据库 技术分享 - CodeSec
Viewing all articles
Browse latest Browse all 3160

If You Read One Article About Split String in SQL SERVER 2016s Read this One #3

$
0
0

If You Read One Article About Split String in SQL SERVER 2016s Read this One #3
Rajat Jaiswal-337252

I am Rajat Jaiswal. I have around 9 years of industry experience. I have always found technology and programming to be very interesting and for me, programming is not something that ends when I step out of the office. I love exploring new stuff and databases amuse me the most. I started blogging in 2006 on http://rajatjaiswal.blogspot.com and http://indiandotnet.wordpress.com, http://sqlRaaga.blogspot.com I am quite active on my blogs and often post entries on Microsoft technologies like C#, ASP.NET, SQL Server, Silverlight & windows Phone 7.

If You Read One Article About Split String in SQL SERVER 2016s Read this One #3 Posted on 22 October 2016 Comments

In the Series of SQL SERVER 2016, this is another post. Before Jumping in detail just think if you have a comma or other separator string and if you have to split it by separator field then for such task in previous SQL SERVER versions either you will write a function which split the string and return desire values in a column or

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


If You Read One Article About Split String in SQL SERVER 2016s Read this One #3

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.


If You Read One Article About Split String in SQL SERVER 2016s Read this One #3

And once this function is created you can use like below


If You Read One Article About Split String in SQL SERVER 2016s Read this One #3

Approach 2 :- You can use XML option in SQL SERVER as shown in below


If You Read One Article About Split String in SQL SERVER 2016s Read this One #3

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


If You Read One Article About Split String in SQL SERVER 2016s Read this One #3

Isn’t it easy ?

I hope you will like this easy way to split the string.

Provide your feedback.


Viewing all articles
Browse latest Browse all 3160

Trending Articles