22,302
社区成员




create table AC_Key
(
Id int primary key identity(1,1),
KeyWords varchar(100)
)
insert into AC_Key
select '联合卡车,卡车,' union
select '东风,卡车' union
select '商用车,卡车,' union
select '卡车,'
select * from AC_Key
select id, case
when charindex(',卡车',keywords)>1 then replace(keywords,',卡车',',')
else keywords end as keywords
into #tmp
from ac_key
select id, case
when charindex('卡车,',keywords)=1 then substring(keywords,4,len(keywords)-3)
else keywords end
from #tmp
create table AC_Key
(
Id int primary key identity(1,1),
KeyWords varchar(100)
)
insert into AC_Key
select '联合卡车,卡车,' union
select '东风,卡车' union
select '商用车,卡车,' union
select '卡车,'union
select '卡车,卡车' union
select '卡车,联合卡车,卡车'
update AC_Key
set KeyWords=stuff(REPLACE(','+KeyWords,',卡车,',','),1,1,'')
select * from AC_Key
/*1 东风,卡车
2
3 卡车
4 联合卡车,卡车
5 联合卡车,
6 商用车,*/
update AC_Key set KeyWords=stuff(REPLACE(','+KeyWords,',东风,',','),1,1,'')
select id, case
when charindex(',卡车',keywords)>1 then replace(keywords,',卡车',',')
else keywords end as keywords
into #tmp
from ac_key
select id, case
when charindex('卡车,',keywords)=1 then substring(keywords,4,len(keywords)-3)
else keywords end
from #tmp
drop table Ac_Key
create table AC_Key
(
Id int primary key identity(1,1),
KeyWords varchar(100)
)
insert into AC_Key
select '联合卡车,卡车,商用车,' union
select '东风,卡车,' union
select '商用车,卡车,' union
select '卡车,'
update AC_Key
set KeyWords=stuff(REPLACE(','+KeyWords,',卡车,',','),1,1,'')
select * from AC_Key
/*
Id KeyWords
1 东风,
2
3 联合卡车,商用车,
4 商用车,
*/
drop table Ac_Key
create table AC_Key
(
Id int primary key identity(1,1),
KeyWords varchar(100)
)
insert into AC_Key
select '联合卡车,卡车,商用车' union
select '东风,卡车,' union
select '商用车,卡车,' union
select '卡车,'
update AC_Key
set KeyWords=stuff(REPLACE(','+KeyWords,',卡车,',','),1,1,'')
select * from AC_Key
/*
Id KeyWords
1 东风,
2
3 联合卡车,商用车
4 商用车,
*/
drop table Ac_Key
create table AC_Key
(
Id int primary key identity(1,1),
KeyWords varchar(100)
)
insert into AC_Key
select '联合卡车,卡车,商用车' union
select '东风,卡车,' union
select '商用车,卡车,' union
select '卡车,'
create table AC_Key
(
Id int primary key identity(1,1),
KeyWords varchar(100)
)
insert into AC_Key
select '联合卡车,卡车,' union
select '东风,卡车,' union
select '商用车,卡车,' union
select '卡车,'
go
update AC_Key set KeyWords=stuff(REPLACE(','+KeyWords,',卡车,',''),1,1,'')
select * from AC_Key
drop table AC_Key
Id KeyWords
----------- ----------------------------------------------------------------------------------------------------
1 东风
2 NULL
3 联合卡车
4 商用车
(4 行受影响)
create table AC_Key
(
Id int primary key identity(1,1),
KeyWords varchar(100)
)
insert into AC_Key
select '联合卡车,卡车,' union
select '东风,卡车,' union
select '商用车,卡车,' union
select '卡车,'
select * from AC_Key
update AC_Key set KeyWords=REPLACE(','+KeyWords,',卡车,','')
select * from AC_Key
/*
Id KeyWords
1 ,东风
2
3 ,联合卡车
4 ,商用车
*/
exec cx '卡车'
/*1 东风
2 东风,
3
4
5 联合卡车
6 联合卡车,
7 联合卡车,商用车
8 商用车,*/
CREATE procedure CX(@s varchar(20))
as
select id, keywords as y,case
when charindex(','+@s+',',keywords)>1 then replace(keywords,','+@s+',',',')
else keywords end as keywords
into #tmp
from ac_key
--select * from #tmp
select id, keywords as y,case
when charindex(','+@s,keywords)>1 then replace(keywords,','+@s,'')
else keywords end as keywords
into #tmp1
from #tmp
--select * from #tmp1
select id,y, case
when charindex(@s,keywords)=1 then substring(keywords,len(@s)+1,len(keywords)-len(@s))
else keywords end as keywords
into #tmp2
from #tmp1
select id,y, case
when charindex(',',keywords)=1 then right(keywords,len(keywords)-1)
else keywords end
from #tmp2