Replace with wildcard, in SQL

后端 未结 6 781
孤独总比滥情好
孤独总比滥情好 2020-12-19 01:46

I know MS T-SQL does not support regular expression, but I need similar functionality. Here\'s what I\'m trying to do:

I have a varchar table field which stores a b

6条回答
  •  既然无缘
    2020-12-19 02:15

    declare @test1 nvarchar(max)
    set @test1='/ID1:Category1/ID2:Category2/ID3:Category3/'
    while(CHARINDEX('ID',@test1)<>0)
    Begin
    select @test1=REPLACE(@test1,SUBSTRING(@test1,CHARINDEX('ID',@test1),CHARINDEX(':',@test1)-
    CHARINDEX('ID',@test1)+1),'') 
    End
    select @test1
    

提交回复
热议问题