SQL 2000 更改中间的字

来源:百度知道 编辑:UC知道 时间:2024/05/25 07:51:00
例表 A
aa 列名
2207-001231
2007-0045672
2007-001234
2007-0123445
2008-0021446
2007789456
要把 2007-00开头的 后面4位的数字··
改成 2007-0 在加 后面4位数字··
附带:有的 后面有的有空格··不能算位数··
`上面一个看起来好 难懂啊```我还是个新手``
补充下``我说的`这只是个例子``那个 文件有几百条``一个个来``很麻烦的呀``
而且 有的 后面有空格呀``如果`是按这来的话```可能会把别的 长度(不算空格位)的 数据也改了也```

update a set aa=stuff(aa,1,7,'2007-0') where left(aa,7)='2007-00'

以上,希望对你有所帮助!

不要第5位吗?

declare @table table
(
aa varchar(20)
)
insert @table
select '2207-001231'union
select '2007-0045672'union
select '2007-001234'union
select '2007-0123445'union
select '2008-0021446'union
select '2007789456'

select * from @table

update @table set aa='2007-0'
+left(replace(aa,'2007-00',''),4)
where aa like '2007-00%'

select * from @table

如果要第五位就把
+left(replace(aa,'2007-00',''),4)
中的4改为5