SQL Server Leading Zeros

It is very easy to get leading zeros from SQL Server and copy/paste the result in Excel

12/12/20231 min read

declare @iInteger int = 12345

declare @tiNumberLeadingZeros tinyint = 10


select Right(Replicate('0',@tiNumberLeadingZeros)+ cast(@iInteger as varchar(10)),@tiNumberLeadingZeros)


Copy leading zeros to Excel:

First mark the target area as 'Text', and then copy/paste