Created
March 11, 2021 19:41
-
-
Save adamnoffie/7fa044434cbc9a5f139d25d611a9287a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- ====================================================================================== | |
-- Author: Adam Nofsinger | |
-- Created: 2013-04-29 | |
-- Description: Utility to return an integer number as a string, padded to X many chars | |
-- with zeros to the left of the number. E.g. Pad(45, 5) = '00045' | |
-- ====================================================================================== | |
CREATE FUNCTION [dbo].[Pad] ( | |
@num integer, | |
@len integer = 3 | |
) RETURNS varchar(100) | |
BEGIN | |
DECLARE @str varchar(100); | |
SET @str = CAST(@num AS varchar); | |
IF @len <= 10 | |
SET @str = RIGHT('000000000'+ @str, @len); | |
ELSE | |
SET @str = REPLICATE('0', @len - LEN(@str)) + @str; | |
RETURN @str; | |
END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment