Skip to content

Commit 97e3a1b

Browse files
author
Matt Usher
authored
Merge pull request #42 from Azure-Samples/sqlextension
Adding the microsoft.rpad function to the Synapse SQL Extension toolkit
2 parents cda49e0 + 006ce36 commit 97e3a1b

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

SQL/Extension/deploy.bat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ sqlcmd -S %_server% -d %_database% -U %_username% -P %_password% -I -i .\functio
5454
sqlcmd -S %_server% -d %_database% -U %_username% -P %_password% -I -i .\functions\microsoft.lpad.sql
5555
sqlcmd -S %_server% -d %_database% -U %_username% -P %_password% -I -i .\functions\microsoft.months_between.sql
5656
sqlcmd -S %_server% -d %_database% -U %_username% -P %_password% -I -i .\functions\microsoft.next_day.sql
57+
sqlcmd -S %_server% -d %_database% -U %_username% -P %_password% -I -i .\functions\microsoft.rpad.sql
5758

5859
ECHO Deploying views
5960

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
IF EXISTS (SELECT * FROM sys.objects WHERE schema_id=SCHEMA_ID('microsoft') AND name = N'rpad')
2+
DROP FUNCTION microsoft.rpad;
3+
GO
4+
5+
CREATE FUNCTION microsoft.rpad(@expression VARCHAR(MAX), @length INT, @fill VARCHAR(64) = ' ')
6+
RETURNS VARCHAR(MAX)
7+
WITH SCHEMABINDING
8+
AS
9+
BEGIN
10+
11+
RETURN
12+
CASE
13+
WHEN (@length <= DATALENGTH(@expression)) THEN LEFT(@expression, @length)
14+
ELSE @expression + LEFT(REPLICATE(@fill, @length), ABS(@length - DATALENGTH(@expression)))
15+
END
16+
17+
END
18+
GO

0 commit comments

Comments
 (0)