Split a delimited string into rows in SQL Server 2016+

STRING_SPLIT is a really helpful function available in SQL Server 2016+. It allows us to split a string into rows based on a specified delimiter. 

In the below example the Tags column for ProductId 1 contains four comma separated values which gets turned into four rows using STRING_SPLIT.

Ideally we wouldn’t have many (or any) character delimited columns in our DBs as it’s a completely denormalized way of storing data which has issues… BUT… if we do have them STRING_SPLIT is definitely helpful. 

Leave a Reply

Your email address will not be published. Required fields are marked *