Skip to content

Commit

Permalink
Merge pull request #61 from Azure-Samples/sqlextension
Browse files Browse the repository at this point in the history
Adding the Teradata GETBIT function to the toolkit
  • Loading branch information
Matt Usher authored Nov 13, 2020
2 parents bce74eb + c8b1d75 commit ed352db
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 5 deletions.
14 changes: 9 additions & 5 deletions SQL/Extension/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,17 @@ The Azure Synapse SQL Extension will install a collection of vies to your Synaps

## Version History

### v0.9.0.0 (September 2nd, 2020)
Version 0.9.0.0 adds the following:
### November 12th, 2020
What's new:

- [Function]: The `microsoft.getbit` script installs a function that emulates the `TD_SYSFNLIB.GETBIT(argument, bit)` Teradata function.

### September 2nd, 2020
What's new:

- [Function]: The `microsoft.btrim` script installs a function that emulates the `TRIM(BOTH 'trim_characters' FROM expression)` Teradata function.
- [Function]: The `microsoft.ltrim` script installs a function that emulates the `TRIM(LEADING 'trim_characters' FROM expression)` Teradata function.
- [Function]: The `microsoft.rtrim` script installs a function that emulates the `TRIM(TRAILING 'trim_characters' FROM expression)` Teradata function.

### v0.8.0.0 (August 4th, 2020)

Version 0.8.0.0 is the initial public release of the Azure Synapse SQL Extension toolkit.
### August 4th, 2020
The initial public release of the Azure Synapse SQL Extension toolkit.
1 change: 1 addition & 0 deletions SQL/Extension/deploy.bat
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ sqlcmd -S %_server% -d %_database% -U %_username% -P %_password% -I -i .\functio
sqlcmd -S %_server% -d %_database% -U %_username% -P %_password% -I -i .\functions\microsoft.asinh.sql
sqlcmd -S %_server% -d %_database% -U %_username% -P %_password% -I -i .\functions\microsoft.btrim.sql
sqlcmd -S %_server% -d %_database% -U %_username% -P %_password% -I -i .\functions\microsoft.dayoccurrence_of_month.sql
sqlcmd -S %_server% -d %_database% -U %_username% -P %_password% -I -i .\functions\microsoft.getbit.sql
sqlcmd -S %_server% -d %_database% -U %_username% -P %_password% -I -i .\functions\microsoft.initcap.sql
sqlcmd -S %_server% -d %_database% -U %_username% -P %_password% -I -i .\functions\microsoft.instr.sql
sqlcmd -S %_server% -d %_database% -U %_username% -P %_password% -I -i .\functions\microsoft.lpad.sql
Expand Down
3 changes: 3 additions & 0 deletions SQL/Extension/functions/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ The `microsoft.btrim` script installs a function that emulates the `TRIM(BOTH 't
## microsoft.dayoccurrence_of_month
The `microsoft.dayoccurrence_of_month` script installs a function that emulates the `DAYOCCURRENCE_OF_MONTH(expression)` Teradata function.

## microsoft.getbit
The `microsoft.getbit` script installs a function that emulates the `TD_SYSFNLIB.GETBIT(argument, bit)` Teradata function.

## microsoft.initcap
The `microsoft.initcap` script installs a function that emulates the `INITCAP(expression)` Teradata function.

Expand Down
31 changes: 31 additions & 0 deletions SQL/Extension/functions/microsoft.getbit.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
IF EXISTS (SELECT * FROM sys.objects WHERE schema_id=SCHEMA_ID('microsoft') AND name = N'getbit')
DROP FUNCTION microsoft.getbit;
GO

CREATE FUNCTION microsoft.getbit(@value INT, @position INT)
RETURNS BIT
WITH SCHEMABINDING
AS
BEGIN

-- Fast opt out for NULL values
IF (@value IS NULL OR @position IS NULL)
RETURN NULL;

DECLARE @temp_value VARCHAR(1000) = '';

WHILE (@value != 0)
BEGIN
IF (@value % 2 = 0)
SET @temp_value = '0' + @temp_value;
ELSE
SET @temp_value = '1' + @temp_value;

SET @value = @value / 2;

END;

RETURN SUBSTRING(REVERSE(@temp_value), @position + 1, 1);

END;
GO

0 comments on commit ed352db

Please sign in to comment.