--借用一楼,改改 update #test set filed=replace(filed,'a','cccc') where substring(filed,1,1)=a
update 表 set 字段=stuff(字段,charindex('a',字段),1,'cccc')
update 表 set 字段=stuff(字段,charindex('a',字段),1,'cccc') 这一个是正解!
update 表 set 字段=stuff(字段,charindex('a',字段),1,'cccc') ======== 如果字段中没有a 会把该字段置NULLupdate #test set field=stuff(field,1,1,'cccc') where substring(field,1,1)='a' select * from #test
--update 表 set 字段=stuff(字段,charindex('a',字段),1,'cccc') --这个好!比我的好!:)
update 表 set 字段=stuff(字段,charindex('a',字段),1,'cccc') where charindex('a',字段)<>0
update #test
set filed=replace(filed,'a','cccc')
where substring(filed,1,1)=a
这一个是正解!
========
如果字段中没有a 会把该字段置NULLupdate #test
set field=stuff(field,1,1,'cccc')
where substring(field,1,1)='a'
select * from #test
--这个好!比我的好!:)
"update 表 set 字段=stuff(字段,charindex('a',字段),1,'cccc')"这个方法是错误的.
vivianfdlpw的是正解.STUFF ( character_expression , start , length , character_expression )
参数
start
是一个整形值,指定删除和插入的开始位置。如果 start 或 length 是负数,则返回空字符串。如果 start 比第一个 character_expression 长,则返回空字符串。
注释:tb_name :表名
col_name :列名