27,579
社区成员
发帖
与我相关
我的任务
分享
update tb set LAC=replicate('0',5-len(LAC))+rtrim(LAC)
[/quote]
谢谢,完美解决
update tb set LAC=replicate('0',5-len(LAC))+rtrim(LAC)
[/quote]
--> 不对呀! LAC字段是float数据类型,数值前导0会自动取消的.
要用字符型(如varchar)的字段来存你要的数据喔.
update tb set LAC=replicate('0',5-len(LAC))+rtrim(LAC)
with t as
(
select 203 LAC
union all select 2
union all select 3456
)
select stuff(convert(varchar(20), 100000+LAC),1,1,'') as LAC
from t
create table tb(LAC float)
insert into tb(LAC)
select 203 union all
select 2 union all
select 3456
select replicate('0',5-len(LAC))+rtrim(LAC) 'LAC' from tb
/*
LAC
-------------------------
00203
00002
03456
(3 row(s) affected)
*/
with tb(LAC)as(
select 203 union
select 2 union
select 3456
)
select case LEN(LAC)
when 1 then '0000'+CONVERT(varchar,LAC)
when 2 then '000'+CONVERT(varchar,LAC)
when 3 then '00'+CONVERT(varchar,LAC)
when 4 then '0'+CONVERT(varchar,LAC)
end
from tb