Logo

PADLEFT

Updated 2023-11-09 21:27:39.637000

Syntax

SELECT [westclintech].[wct].[PADLEFT] (
  <@Text, nvarchar(max),>
 ,<@TotalWidth, int,>
 ,<@PaddingChar, nvarchar(1),>)

Description

Use the scalar function PADLEFT to place characters at the beginning of a string of text, when the length of the text is less than the specified width.

Arguments

@PaddingChar

the character to be used for padding. The @PaddingChar argument can be of data types that are implicitly convertible to nvarchar or ntext.

@TotalWidth

the minimum length of the result, including padding. The @Totalwidth argument can be an expression of types that are implicitly convertible to int.

@Text

the text to be padded. The @Text argument can be of data types that are implicitly convertible to nvarchar or ntext.

Return Type

nvarchar(max)

Remarks

If LEN(@Text) = @TotalWidth, then @Text is returned.

If @TotalWidth < 0, then an error is returned.

If @TotalWidth is NULL, then an error is returned.

If @PaddingChar is null, then SPACE is used.

If @PaddingChar is blank, then SPACE is used.

If you want to indent @Text, consider using the INDENT function.

Examples

select wct.PADLEFT('abc'
,10
,' ');

This produces the following result.

{"columns":[{"field":"column 1"}],"rows":[{"column 1":"       abc"}]}