一个字段的值是这样的:
,1,5,6,8,12,15,14,22,51
我想把其中的5去掉,变成
,1,6,8,12,15,14,22,51
怎样写比较简单?其中这个,5也可能在最后面:,1,6,8,12,15,14,22,51,5
,1,5,6,8,12,15,14,22,51
我想把其中的5去掉,变成
,1,6,8,12,15,14,22,51
怎样写比较简单?其中这个,5也可能在最后面:,1,6,8,12,15,14,22,51,5
insert into tb
select '23,3,34,5,22,30,5,20,532,25,10'
union all
select '5,23423,45,55,25,23,5'select replace(replace(code+',','5,',','),',,',',')
from tbdrop table tb
Insert @TEST Select ',1,5,6,8,12,15,14,22,51'
Union All Select ',1,6,8,12,15,14,22,51,5'
Union All Select ',5,1,6,8,12,15,14,22,51'Declare @I Int
Select @I = 5
Select Left(Replace(Code + ',', ',' + Rtrim(@I) + ',', ','), Len(Code) - Len(@I) - 1) From @TEST
--Result
/*
,1,6,8,12,15,14,22,51
,1,6,8,12,15,14,22,51
,1,6,8,12,15,14,22,51
*/
Insert @TEST Select ',1,5,6,8,12,15,14,22,51'
Union All Select ',1,6,8,12,15,14,22,51,5'
Union All Select ',5,1,6,8,12,15,14,22,51'Declare @I Int
Select @I = 5
Update @TEST Set Code = Left(Replace(Code + ',', ',' + Rtrim(@I) + ',', ','), Len(Code) - Len(@I) - 1)Select * From @TEST
--Result
/*
,1,6,8,12,15,14,22,51
,1,6,8,12,15,14,22,51
,1,6,8,12,15,14,22,51
*/