Search notes:

SQL Server helpers

Some helper functions for development on SQL Server

rpad

rpad(@txt, @len) returns a string whose length is @len. If len(@txt) is smaller than @len, the returned string is @txt whose right side is padded with spaces, otherwise, @txt is truncated on the right side.
create or alter function dbo.rpad(
   @txt  varchar(max),
   @len  int
)   returns varchar(max)
as begin
    return left(coalesce(@txt, '') + space(4000), @len)
end;
go
Github repository SQL-Server-helpers, path: /rpad.sql

rremove

rremove(@string, @len) removes @len characters from the right side of @string and returns the resulting value.
If @len is greater than len(@string), an empty string is returned.
create or alter function dbo.rremove(
   @txt   nvarchar(max),
   @len   int
)   returns nvarchar(max)
as begin
    if len(@txt) < @len return ''

    return left(@txt, len(@txt) - @len)
end;
go
Github repository SQL-Server-helpers, path: /rremove.sql

Index