继续 寻:

Hanes 2004-08-31 02:29:55
有一大批数据
数据库中的某个字段(如编号),字符型
以10,20,30....等开头,长度不一定
现要在更改以10开头的编号,在编号10后面插入几个字符,其它字符保持不变
如何用sql语句实现?
...全文
123 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
老宛 2004-08-31
  • 打赏
  • 举报
回复
--测试

create table #t(
id int identity(1,1),
a varchar(50)
)
insert into #t select '10abc'
insert into #t select '10aadbc'
insert into #t select '130fdabc'
insert into #t select '10aadbc'
insert into #t select '20abfac'
insert into #t select '10abc'
--先看看原始数据
select * from #t
--修改
update #t set a=case when left(a,2)='10' then left(a,2)+'[string]'+substring(a,3,len(a)-2) else a end
--新的结果
select * from #t

drop table #t
tx1icenhe 2004-08-31
  • 打赏
  • 举报
回复
update tablename
set fieldname=STUFF(fieldname,3,0,'插入的字符')
where fieldname like '10%'

饮水需思源 2004-08-31
  • 打赏
  • 举报
回复
update tablename set 编号=编号+'aaa'+right(编号,len(编号)-2) where left(编号,2)='10'

34,838

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧