SQL Eval Function String_PadRight

String_PadRight returns a new string that left-aligns the characters in the source string by padding them on the right with a specified paddingChar Unicode character, for a specified total length.

String_PadRight (
	@source NVARCHAR (MAX),
	@totalWidth INT, 
	@paddingChar NVARCHAR (1)
	)
RETURNS NVARCHAR (MAX)

Parameters

  • source: The source string.
  • totalWidth: The number of characters in the resulting string, equal to the number of original characters plus any additional padding characters.
  • paddingChar: A Unicode padding character.

Returns

  • A new string that is equivalent to the source string, but right-aligned and padded on the left with as many paddingChar characters as needed to create a length of totalWidth.
  • If totalWidth is less than the length of the source string, the method returns a reference to the existing instance.
  • If totalWidth is equal to the length of the source string, the method returns a new string that is identical to the source string.

Example

SELECT SQLNET::String_PadRight('This is a String.', 20, '.')
SELECT SQLNET::String_PadRight('This is a String.', 10, '.')

String_PadRight4k

It is equivalent to String_PadRight except no NVARCHAR(MAX) parameters; it can be used when input data will never be over 4000 characters as this function offers better performance.

String_PadRight4k (
	@source NVARCHAR (4000),
	@totalWidth INT, 
	@paddingChar NVARCHAR (1)
	)
RETURNS NVARCHAR (4000)

Example

SELECT SQLNET::String_PadRight4k('This is a String.', 20, '.')
SELECT SQLNET::String_PadRight4k('This is a String.', 10, '.')


Contents