Mid
String / TVF
SQL & Databases
How do you split a comma-separated string into rows in SQL Server?
Short answer: Use STRING_SPLIT (SQL Server 2016+), or OPENJSON, or a numbers table. Note STRING_SPLIT historically lacked guaranteed order unless using the enable_ordinal parameter on newer versions.
Sample solution
T-SQL
SELECT LTRIM(RTRIM(value)) AS Tag
FROM STRING_SPLIT('sql,interview,t-sql', ',');
Ask about ordering requirements before picking STRING_SPLIT.
Share this Q&A
Share preview image: https://www.toolliyo.com/images/toolliyo-logo.png