출처 : http://www.sqler.com/?mid=bSQLQA&listStyle=webzine&document_srl=407559






IF OBJECT_ID('tbl') IS NOT NULL

 DROP TABLE tbl

GO

CREATE TABLE tbl

(

idx int ,

 value VARCHAR(MAX)

)

GO

INSERT INTO tbl

SELECT 1, ' 123 , 456 , 789 , 321 '

GO

 

SELECT a.idx ,LTRIM(RTRIM(SUBSTRING(a.value,b.s,b.e-b.s))) AS Split

  FROM tbl a

 CROSS APPLY ( SELECT number AS s, CHARINDEX(',',a.value+',',number+1) AS e

     FROM master..spt_values

    WHERE number = CHARINDEX(',',','+a.value,number)

      AND type ='P' ) b

GO








Posted by motolies
,