RPAD Function

RPAD returns char1, right-padded to length n with char2, replicated as many times as necessary; char2 defaults to a single blank. If char1 is longer than n, this function <BR>returns the portion of char1 that fits in n. <BR>The argument n is the total length of the return value as it is displayed on your terminal screen. In most character sets, this is also the number of characters in the return value.

CREATE     FUNCTION RPAD(
@Char1 VARCHAR(8000), 
@n 	INT, 
@Char2 VARCHAR(255) 
			) 
RETURNS VARCHAR(8000)
AS
BEGIN
	IF LEN(@Char1) > @n
	BEGIN
		IF SIGN(@n) = -1
			RETURN SUBSTRING(@Char1,1,0)
		RETURN SUBSTRING(@Char1,1,@n)
	END
	RETURN @Char1+ REPLICATE(@Char2,@n-LEN(@Char1))
END

Rate

3 (2)

Share

Share

Rate

3 (2)