I'm trying to select a bigint field and format it with leading zeros. I've tried the convert function but it does not seem to support this basic feature. There is no reference in the document on CONVERT or CAST, it only refers to formatting dates.
create function LZero(@MyNum int, @MyLength int)
declare @MyStr varchar
set @MyStr = convert(varchar,@MyNum)
set @MyStr = replicate('0',(@MyLength-datalength(@MyStr)))+@MyStr
select dbo.LZero(NumericField,6) from MyTable