DECLARE @num INT
DECLARE @length INT
SET @num=123
SET @length = 10
select REPLICATE('0',@length-DATALENGTH(CONVERT(VARCHAR,@num)))+CONVERT(VARCHAR,@num)
DECLARE @length INT
SET @num=123
SET @length = 10
select REPLICATE('0',@length-DATALENGTH(CONVERT(VARCHAR,@num)))+CONVERT(VARCHAR,@num)