SQL string split
There are different ways to split string in SQL query. One way I came across is using openjson function.
DECLARE @String AS VARCHAR(100) = '1,2,3,4' SELECT value FROM OPENJSON('[' + @String + ']') This method assumed the string using comma as the delimitor. If your string using other character as the delimitor, consider using REPLACE() function to change it to comma first.
Another simple method would be using STRING_SPLIT() function in SQL2016+
Posted by John Liu Monday, November 15, 2021