34,590
社区成员
发帖
与我相关
我的任务
分享
稍微改一下,增加了11在数据第一个位置的处理
--> (让你望见影子的墙)生成测试数据,时间:2009-02-17
if not object_id('tb') is null
drop table tb
Go
Create table tb([id] nvarchar(2),[content] nvarchar(17))
Insert tb
select N'1',N'1,2,3,4,6,9,10,11' union all
select N'2',N'1,3,7,9,11,19' union all
select N'3',N'11,1,2,4,8,20'
Go
Select * from tb
update tb
set content=case when charindex('11',content)=1 then replace(content,'11,','')
else replace(content,',11','') end
where charindex('11',content)>0
select * from tb
1 1,2,3,4,6,9,10
2 1,3,7,9,19
3 1,2,4,8,20
---测试数据---
if object_id('[tb]') is not null drop table [tb]
go
create table [tb]([id] int,[content] varchar(17))
insert [tb]
select 1,'1,2,3,4,6,9,10,11' union all
select 2,'1,3,7,9,11,19' union all
select 3,'1,2,4,8,20'
---查询---
select
id,
replace(replace(content,',11',''),'11,','') as content
from [tb]
---结果---
id content
----------- ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1 1,2,3,4,6,9,10
2 1,3,7,9,19
3 1,2,4,8,20
(所影响的行数为 3 行)
--> (让你望见影子的墙)生成测试数据,时间:2009-02-17
if not object_id('tb') is null
drop table tb
Go
Create table tb([id] nvarchar(2),[content] nvarchar(17))
Insert tb
select N'1',N'1,2,3,4,6,9,10,11' union all
select N'2',N'1,3,7,9,11,19' union all
select N'3',N'1,2,4,8,20'
Go
Select * from tb
update tb
set content=replace(content,',11','')
where charindex('11',content)>0
select * from tb
1 1,2,3,4,6,9,10
2 1,3,7,9,19
3 1,2,4,8,20
create table tb(id int,content varchar(50))
insert into tb select 1,'1,2,3,4,6,9,10,11'
insert into tb select 1,'1,3,7,9,11,19'
insert into tb select 1,'1,2,4,8,20'
update tb set content=replace(','+content+',',',11,','')
select * from tb