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

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1738293850, '18.226.222.3', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/databases/SQL-Server/helpers/index(73): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78