if exists (select 1 from dbo.sysobjects where id=object_id(N'tmp') and OBJECTPROPERTY(id,N'IsUserTable')=1)
drop table tmp;
CREATE TABLE tmp (
id int DEFAULT NULL,
txt varchar(20) DEFAULT NULL
);
insert into tmp values(22,null);
-- 补位函数
select cast(id as varchar)+REPLICATE('0',8-len(id)) from tmp;
select REPLICATE('0',8-len(id))+cast(id as varchar) from tmp;