It was about 4 years ago that I’ve wrote a custom function to split a delimited string in T-SQL. I’ve wrote that because there was no split function for SQL Server at that time. Fortunately SQL Server 2016 comes with new excitements, and built-in split function is one of them.
The new String_Split function is a table function which has two inputs:
String_Split(<main string as input>,<delimiter>)
Usage of it should be within From clause of your query because this is a table function. Here is an example:
select * from string_split('this,is,a,test',',')
and here is the result:
You might only face an issue when the delimiter contains special reserved characters of t-sql, such as single quote: ‘
In those cases you can use another signle quote to escape that especial character.
Trainer, Consultant, Mentor
Reza Rad is a Microsoft Regional Director, an Author, Trainer, Speaker and Consultant. He has a BSc in Computer engineering; he has more than 20 years’ experience in data analysis, BI, databases, programming, and development mostly on Microsoft technologies. He is a Microsoft Data Platform MVP for 12 continuous years (from 2011 till now) for his dedication in Microsoft BI. Reza is an active blogger and co-founder of RADACAD. Reza is also co-founder and co-organizer of Difinity conference in New Zealand, Power BI Summit, and Data Insight Summit.
Reza is author of more than 14 books on Microsoft Business Intelligence, most of these books are published under Power BI category. Among these are books such as Power BI DAX Simplified, Pro Power BI Architecture, Power BI from Rookie to Rock Star, Power Query books series, Row-Level Security in Power BI and etc.
He is an International Speaker in Microsoft Ignite, Microsoft Business Applications Summit, Data Insight Summit, PASS Summit, SQL Saturday and SQL user groups. And He is a Microsoft Certified Trainer.
Reza’s passion is to help you find the best data solution, he is Data enthusiast.
His articles on different aspects of technologies, especially on MS BI, can be found on his blog: https://radacad.com/blog.
1 thought on “Split Function in SQL Server 2016”