Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save zzzprojects/314efd608b6ef9828b16 to your computer and use it in GitHub Desktop.
Save zzzprojects/314efd608b6ef9828b16 to your computer and use it in GitHub Desktop.
-- CREATE test table
DECLARE @SourceTable TABLE
(
RowID INT ,
DelimitedString VARCHAR(8000) ,
ArrayIndex INT
)
INSERT INTO @SourceTable
VALUES ( 1, 'a;b;c;d;e', 0 ),
( 2, 'a;b;c;d;e', 2 ),
( 3, 'a;b;c;d;e', 4 )
-- DECLARE expression to evaluate
DECLARE @sqlnet SQLNET = SQLNET::New('Split(s, ";")[i]')
-- 1 | a | 0
-- 2 | c | 2
-- 3 | e | 4
SELECT RowID ,
@sqlnet.ValueString('s', DelimitedString).ValueInt('i', ArrayIndex).EvalString(),
ArrayIndex
FROM @SourceTable
ORDER BY RowID
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment