向Sql Server表中字段追加某字符串
如下表[dbo.ench]:id/en/word1/Shehasgone[go]/go2/gohome/go3/gonewithwind/go4/Helookedabou...
如下表[dbo.ench]:
id/en/word
1/ She has gone[go]/go
2/go home/go
3/gone with wind/go
4/He looked about.[about]/about
【注意:ID=1的英语句已经包含[go]】要改造成:
id/en/word
1/ She has gone[go]/go
2/go home/go
3/gone with wind[go]/go
4/He looked about.[about]/about
【注意,ID=3的追加了[go],但ID=1的没有重复添加;添加的规则是根据word列】
我的说明您明白么?请问如何用Sql语句或存储过程实现?
【注意】
ID为2的仍保持不变:
2/go home/go 展开
id/en/word
1/ She has gone[go]/go
2/go home/go
3/gone with wind/go
4/He looked about.[about]/about
【注意:ID=1的英语句已经包含[go]】要改造成:
id/en/word
1/ She has gone[go]/go
2/go home/go
3/gone with wind[go]/go
4/He looked about.[about]/about
【注意,ID=3的追加了[go],但ID=1的没有重复添加;添加的规则是根据word列】
我的说明您明白么?请问如何用Sql语句或存储过程实现?
【注意】
ID为2的仍保持不变:
2/go home/go 展开
4个回答
展开全部
declare @word varchar(100),@en varchar(100),@newen
declare 游标名 cursor
for select [en],[word] from ench where id not in (select a.[id] from ench a where a.[en] like '% 'a.[word]' %' or a.[word]' %' or '% 'a.[word])
open 游标名
fetch next from 游标名 into @en,@word
while @@fetch_status = 0
begin
set @newen=@en+'['+@word+']'
update ench
set [en]=@newen
where [en]=@en and [word]=@word
fetch enxt from 游标名 into @en,@word
end
close 游标名
deallocate 游标名
麻烦了点 不知道好不好用 记录要是少的话 用用还可以
简单的想不出来 你自己研究吧
----------------------------------------------------------------
declare @word varchar(100),@en varchar(100),@newen
declare 游标名 cursor
for select [en],[word] from ench where id<>2 and id not in (select a.[id] from ench a where a.[en] like '% 'a.[word]' %' or a.[word]' %' or '% 'a.[word])
open 游标名
fetch next from 游标名 into @en,@word
while @@fetch_status = 0
begin
set @newen=@en+'['+@word+']'
update ench
set [en]=@newen
where [en]=@en and [word]=@word
fetch enxt from 游标名 into @en,@word
end
close 游标名
deallocate 游标名
declare 游标名 cursor
for select [en],[word] from ench where id not in (select a.[id] from ench a where a.[en] like '% 'a.[word]' %' or a.[word]' %' or '% 'a.[word])
open 游标名
fetch next from 游标名 into @en,@word
while @@fetch_status = 0
begin
set @newen=@en+'['+@word+']'
update ench
set [en]=@newen
where [en]=@en and [word]=@word
fetch enxt from 游标名 into @en,@word
end
close 游标名
deallocate 游标名
麻烦了点 不知道好不好用 记录要是少的话 用用还可以
简单的想不出来 你自己研究吧
----------------------------------------------------------------
declare @word varchar(100),@en varchar(100),@newen
declare 游标名 cursor
for select [en],[word] from ench where id<>2 and id not in (select a.[id] from ench a where a.[en] like '% 'a.[word]' %' or a.[word]' %' or '% 'a.[word])
open 游标名
fetch next from 游标名 into @en,@word
while @@fetch_status = 0
begin
set @newen=@en+'['+@word+']'
update ench
set [en]=@newen
where [en]=@en and [word]=@word
fetch enxt from 游标名 into @en,@word
end
close 游标名
deallocate 游标名
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
按照你说的规则ID=2应该为2/go home[go]/go才对,但先不管了,下面的应该有点接近了。
update ench set en=en+'['+word+']' where charindex(word,en)=0
update ench set en=en+'['+word+']' where charindex(word,en)=0
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
update dbo.ench set en=en+'[go]' where word='go' and charindex('[go]',en)=0
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
为什么不直接update该字段
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询