How to split a comma-separated value to columns

后端 未结 30 3968
刺人心
刺人心 2020-11-21 04:38

I have a table like this

Value   String
-------------------
1       Cleo, Smith

I want to separate the comma delimited string into two colu

30条回答
  •  一生所求
    2020-11-21 04:58

    DECLARE @INPUT VARCHAR (MAX)='N,A,R,E,N,D,R,A'
    DECLARE @ELIMINATE_CHAR CHAR (1)=','
    DECLARE @L_START INT=1
    DECLARE @L_END INT=(SELECT LEN (@INPUT))
    DECLARE @OUTPUT CHAR (1)
    
    WHILE @L_START <=@L_END
    BEGIN
        SET @OUTPUT=(SUBSTRING (@INPUT,@L_START,1))
        IF @OUTPUT!=@ELIMINATE_CHAR
        BEGIN
            PRINT @OUTPUT
        END
        SET @L_START=@L_START+1
    END
    

提交回复
热议问题