34,571
社区成员
发帖
与我相关
我的任务
分享
declare @id int
set @id = 1
select right(10000+@id,4)
declare @id int
set @id = 1
select right(10000+@id,4)
create table tb
(id int identity,
name varchar(10),
code int)
go
insert tb(name) select 'A'
union all select 'B'
union all select 'C'
union all select 'D'
select * ,code=right('000'+cast(id as varchar),5)
from tb
drop table tb
---
id name code code
1 A NULL 0001
2 B NULL 0002
3 C NULL 0003
4 D NULL 0004