Code Snippet Details

<- Back to List


Language
T-SQL
Description
Pad left function
Code
USE [DBName] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE Function [Utility].[udf_PadLeft] ( @Value VARCHAR(200) ,@PadCharacter CHAR(1)='0' ,@Length INT ) RETURNS VARCHAR(20) /*====================================================================================================================== DESCRIPTION: Pad Left utility function EXAMPLE USE: SELECT Utility.udf_PadLeft('123456','0',14) Result: 00000000123456 CHANGE HISTORY: Date Developer Ref Comments ------------------------------------------------------------------------------------------------------------------------ 06/08/2014 Andy Creigh Initial version. ======================================================================================================================*/ AS BEGIN RETURN REPLICATE(@PadCharacter,@Length - Len(@Value))+@Value END