SQL根据逗号分割


   INSERT INTO #temp_stringSplit (value) VALUES((@str))
   SELECT 
  SUBSTRING(T.[value],R.number,CHARINDEX(',',T.[value]+',',R.number)-R.number) AS value
  INTO #temp
FROM #temp_stringSplit AS T
JOIN (
    SELECT TOP 10 number FROM  [master].dbo.spt_values  
    WHERE [type]='P' ORDER BY number)AS R ON (CHARINDEX(',',','+T.[value],R.number)=R.number)

    DECLARE @index INT 
    SELECT @index = COUNT(*) FROM #temp

    DECLARE @i INT =0
    while @i< @index
    BEGIN
        DECLARE @rowindex int = 0
        SELECT TOP 1 @rowindex = value FROM #temp 
        print @rowindex
        DELETE #temp WHERE value = @rowindex
        SET @i = @i+1
    END

 

 

你可能感兴趣的:(SQL)