有表A
id path
----------------
s1 qwerxio
s2 uipxkl
s3 hjlxkhf
s4 cvbmndfhu
s5 sdexyhn其中path字段是CHAR型,path中的每个字母最多只会在内容中出现一次
现需要更新s1,s3,s5三条记录的path字段,使其内容中的'x'字母前的内容更新为'12345','x'字母及其后的内容保持不变
即更新后,s1,s3,s5的path内容为:
id path
----------------
s1 12345xio
s3 12345xkhf
s5 12345xyhn最坏的方法是分3条update语句,更新这三条记录
请问有没有更好的方法,可以提高update的效率呢? 包括在程序中进行字符串处理后在写入数据库的方法,只要效率高就可以了
急啊,请各位高手帮忙一下,非常谢谢!!!!!
id path
----------------
s1 qwerxio
s2 uipxkl
s3 hjlxkhf
s4 cvbmndfhu
s5 sdexyhn其中path字段是CHAR型,path中的每个字母最多只会在内容中出现一次
现需要更新s1,s3,s5三条记录的path字段,使其内容中的'x'字母前的内容更新为'12345','x'字母及其后的内容保持不变
即更新后,s1,s3,s5的path内容为:
id path
----------------
s1 12345xio
s3 12345xkhf
s5 12345xyhn最坏的方法是分3条update语句,更新这三条记录
请问有没有更好的方法,可以提高update的效率呢? 包括在程序中进行字符串处理后在写入数据库的方法,只要效率高就可以了
急啊,请各位高手帮忙一下,非常谢谢!!!!!
解决方案 »
- sqlserver恢复模式为simple,是否还可以进行事务复制
- 最近在看邹建大哥写的<SQL Server 2000开发与管理应用实例>
- 这样的SQL语句该怎么写?
- 一个调用存储过程获得返回值问题?郁闷已久高人支招啊
- 加工单价工序计算请教
- 如何将数据库由拉丁文字符集server导到繁体server中,包括库中所有object和data,最主要是varchar类型data?
- 如何在SQL SERVER 2000 中合并记录?
- 后缀为.db的数据库文件如何导入sql server?
- 一个查询问题
- 请 CrazyFor(蚂蚁),大力等高手帮忙!!
- 请教一条查询语句
- ++++求一条SQL语句++++
set path = '12345' + substring(path , charindex('x',path)+1 , len(path))
where id in ('s1','s3','s5')
insert into A values('s1', 'qwerxio')
insert into A values('s2', 'uipxkl')
insert into A values('s3', 'hjlxkhf')
insert into A values('s4', 'cvbmndfhu')
insert into A values('s5', 'sdexyhn')
goupdate A
set path = '12345' + substring(path , charindex('x',path) , len(path))
where id in ('s1','s3','s5')select * from Adrop table A/*
id path
---------- --------------------
s1 12345xio
s2 uipxkl
s3 12345xkhf
s4 cvbmndfhu
s5 12345xyhn
(所影响的行数为 5 行)
*/
declare @T table (id varchar(2),path varchar(9))
insert into @T
select 's1','qwerxio' union all
select 's2','uipxkl' union all
select 's3','hjlxkhf' union all
select 's4','cvbmndfhu' union all
select 's5','sdexyhn'update @T set [path] = stuff([path],1,charindex('x',[path])-1,'12345') where id in ('s1','s2','s3')
-- OR 龟兄
select * from @T
insert into @tb select 's1','qwerxio'
insert into @tb select 's2','uipxkl'
insert into @tb select 's3','hjlxkhf'
insert into @tb select 's4','cvbmndfhu'
insert into @tb select 's5','sdexyhn'
update t set path=case when charindex('x',path)>0 then stuff(path,1,charindex('x',path)-1,'12345') else path end
from @tb t where right(id,1)%2<>0
select * from @tbs1 12345xio
s2 uipxkl
s3 12345xkhf
s4 cvbmndfhu
s5 12345xyhn
insert into @tb select 's1','qwerxio'
insert into @tb select 's2','uipxkl'
insert into @tb select 's3','hjlxkhf'
insert into @tb select 's4','cvbmndfhu'
insert into @tb select 's5','sdexyhn'update t set path=stuff(path,1,charindex('x',path)-1,'12345')
from @tb t where right(id,1)%2<>0select * from @tbs1 12345xio
s2 uipxkl
s3 12345xkhf
s4 cvbmndfhu
s5 12345xyhn
set path = '12345' + substring(path , charindex('x',path)+1 , len(path))
where id in ('s1','s3','s5')
from test where name like '%x%'
from a where path like '%x%'