출처1 : http://blog.aliencube.org/ko/2014/02/10/converting-array-like-table-from-string-in-ms-sql/
출처2 : http://stackoverflow.com/questions/2647/how-do-i-split-a-string-so-i-can-access-item-x
출처3 : http://www.codeproject.com/Articles/7938/SQL-User-Defined-Function-to-Parse-a-Delimited-Str
DECLARE @items NVARCHAR(MAX)
SET @items = '111,222,333,444,555,666,777,888,999'
DECLARE @delimiter NVARCHAR(1)
SET @delimiter = ','
DECLARE @item NVARCHAR(MAX)
SET @item = NULL
DECLARE @results TABLE (
Item NVARCHAR(MAX)
)
WHILE LEN(@items) > 0
BEGIN
DECLARE @index INT
SET @index = PATINDEX('%' + @delimiter + '%', @items)
IF @index > 0
BEGIN
SET @item = SUBSTRING(@items, 0, @index)
SET @items = SUBSTRING(@items, LEN(@item + @delimiter) + 1, LEN(@items))
INSERT INTO @results ( Item ) VALUES ( @item )
END
ELSE
BEGIN
SET @item = @items
SET @items = NULL
INSERT INTO @results ( Item ) VALUES ( @item )
END
END
SELECT * FROM @results