STRING_SPLIT() (SQL Server 2016+)
STRING_SPLIT() (SQL Server 2016+) is a SQL function in the String Functions category. SQL Server 2016+: splits a delimited string into rows. Single-column result set named "value". The syntax is SELECT value FROM STRING_SPLIT(string, delimiter);. It accepts string, delimiter. It returns splitted rows. A typical example: SELECT value FROM STRING_SPLIT('apple,banana,cherry,date', ','); -- apple -- banana -- cherry -- date -- Use with IN clause: DECLARE @ids VARCHAR(100) = '1,3,5,7'; SELECT * FROM products WHERE id IN (SELECT CAST(value AS INT) FROM STRING_SPLIT(@ids, ',')); -- CROSS APPLY for row expansion: SELECT p.name, s.value AS tag FROM products p CROSS APPLY STRING_SPLIT(p.tags, ',') AS s; -- Note: order is NOT guaranteed without explicit ordering A close relative is CONCAT(), which concatenates two or more strings into one string. Returns NULL if any argument is NULL. A close relative is SUBSTRING(), which extracts characters from a string starting at position `start` for `length` characters.