字段值替换,找一个简单的方法
一个字段的值是这样的:
,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
[解决办法]
Declare @TEST Table (Code Varchar(100))
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
*/