34,590
社区成员
发帖
与我相关
我的任务
分享
declare @d varchar(30)
set @d='0036055'
select left(@d,3) --截取前3位,补足3位补足0到3位
+right('000'+substring(@d,4,1),3) --然后截取一位,补足0到3位
+right('0000'+right(@d,3),4) --最后3位先在前面补足0到4位
+'000' --然后再加3个0到7位
/**
----------------------
0030060055000
(所影响的行数为 1 行)
**/
create table #1 (dd nvarchar(25))
insert #1 values('0036055')
insert #1 values('1136346')
go
select dd
,dd2 = '0'+left(dd,2)+'0'+substring(dd,3,2)+'0000'+substring(dd,5,3)
from #1
/*
dd dd2
------------------------- -------------
0036055 0000360000055
1136346 0110360000346
(2 row(s) affected)
*/
declare @generaldata table (宗地号 nvarchar(20))
insert into @generaldata select '0036055'
update @generaldata set 宗地号= LEFT (宗地号,2)+'00'+ substring(宗地号,3,2)+'0000'+RIGHT(宗地号,3)
select * from @generaldata
宗地号
--------------------
0000360000055
(1 行受影响)
declare @d varchar(30)
set @d='0036055'
select right('000000'+left(@d,4),6)+right('0000000'+right(@d,3),7)
/**
-------------------------
0000360000055
(所影响的行数为 1 行)
**/
select '0'+substring('0036055',1,2)+'0'+substring('0036055',3,2)+'0000'+substring('0036055',5,3)
-------------
0000360000055
(1 行受影响)
select left('00'+'0036055',6)+'00000'+right('0036055',2)
/*
0000360000055
*/
use GADJ
go
update GENERALDATA
set 宗地号 = substring(宗地号,1,2) + '00' + substring(宗地号,3,2) + '0000' + substring(宗地号,5,3)
select substring('0036055',1,2) + '00' + substring('0036055',3,2) + '0000' + substring('0036055',5,3)
/*
--------------------
0000360000055
(所影响的行数为 1 行)
*/