字段 Code :S00-0100001
S00-1200045
S00-JA01324
S00-GD00221
现要在Code字段中插入年份:10
得到结果:S00-011000001
S00-121000045
S00-JA1001324
S00-GD1000221
如何写这个SQL,谢谢了!
S00-1200045
S00-JA01324
S00-GD00221
现要在Code字段中插入年份:10
得到结果:S00-011000001
S00-121000045
S00-JA1001324
S00-GD1000221
如何写这个SQL,谢谢了!
set code = left(code,6)+'10'+right(code,5)
set code=left(code,6)+'10'+right(code,len(code)-6)
--> 测试数据: #t
if object_id('tempdb.dbo.#t') is not null drop table #t
go
create table #t (Code varchar(11))
insert into #t
select 'S00-0100001' union all
select 'S00-1200045' union all
select 'S00-JA01324' union all
select 'S00-GD00221'
declare @str varchar(30)
set @str = '10'select left(code,6)+@str+right(code,6)
from #t----------------------------------------------------
S00-0110100001
S00-1210200045
S00-JA10A01324
S00-GD10D00221(所影响的行数为 4 行)
set code = replace(Code ,'S00-','S00-10')
tb
set
code=left(code,6)+'10'+right(code,len(code)-6)