A small change, but a great one, in SQL 2016 is native support for splitting strings.
This has to be about the most common user defined function that people write in SQL Server. I’ve certainly seen it across many companies and clients that I’ve worked for over the years. From use in SSRS, or passing multiple values to stored procedures it’s been fairly ubiquitous.
There are countless blog posts about the best way to do this, it’s virtually a competition amongst the best and brightest SQL minds.
From Jeff Moden’s Tally versions:
Aaron Bertrand has a great post here that outlines many of these methods and does a performance comparison.
(SPOILER : Adam Machanic wins)
With SQL 2016 we have a new way, and apparently it’s even substantially faster that Adam M’s CLR. Figures from Aaron again:
This couldn’t be simpler, but I’ll detail it here briefly. The syntax is:
STRING_SPLIT (string, separator)So in a basic example:
DECLARE @SplitMyString VARCHAR(255) = 'Value1,Value2,Value3,Value4';
And the results: