This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DECLARE @sqlnet SQLNET = SQLNET::New('Regex.Split(input, "/")') | |
SELECT * | |
FROM SourceTable | |
CROSS APPLY dbo.SQLNET_EvalTVF_1(@sqlnet.ValueString('input', DelimitedString)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DECLARE @text VARCHAR(50) = 'a;d;c;b;e'; | |
-- Split (with ';' delimiter) | |
DECLARE @sqlnet SQLNET = SQLNET::New('Regex.Split(input, ";")') | |
SELECT * | |
FROM dbo.SQLNET_EvalTVF_1(@sqlnet.ValueString('input', @text)) | |
-- Split && Distinct | |
SET @sqlnet = @sqlnet.Code('Regex.Split(input, ";").Distinct()') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// using Z.EntityFramework.Plus; // Don't forget to include this. | |
var ctx = new EntitiesContext(); | |
// Oops! All customers are cached instead of the customer count. | |
var count = ctx.Customers.FromCache().Count(); | |
// The count is deferred and cached. | |
var count = ctx.Customers.DeferredCount().FromCache(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// using Z.EntityFramework.Plus; // Don't forget to include this. | |
var ctx = new EntitiesContext(); | |
// The first call perform a database round trip | |
var countries1 = ctx.Countries.FromCache().ToList(); | |
// Subsequent calls will take the value from the memory instead | |
var countries2 = ctx.Countries.FromCache().ToList(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- CREATE test | |
DECLARE @t TABLE (Id INT , Input VARCHAR(MAX)) | |
INSERT INTO @t VALUES ( 1, '1, 2, 3; 4; 5' ), ( 2, '6;7,8;9,10' ) | |
-- SPLIT with many delimiters: ',' and ';' | |
DECLARE @sqlnet SQLNET = SQLNET::New('Regex.Split(input, ",|;")') | |
SELECT * | |
FROM @t AS A | |
CROSS APPLY ( SELECT * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE PROCEDURE [dbo].[Select_Switch] @x INT, @y INT, @z INT | |
AS | |
BEGIN | |
DECLARE @result INT | |
SET @result = SQLNET::New(' | |
switch(x) | |
{ | |
case 1: return y + z; | |
case 2: return y - z; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DECLARE @items TABLE (Quantity INT, Price MONEY) | |
INSERT INTO @items | |
VALUES ( 2, 10 ), | |
( 9, 6 ), | |
( 15, 2 ), | |
( 6, 0 ), | |
( 84, 5 ) | |
DECLARE @customColumn SQLNET = SQLNET::New('(quantity * price).ToString("$#.00")') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DECLARE @tableFormula TABLE (Formula VARCHAR(255), X INT, Y INT, Z INT) | |
INSERT INTO @tableFormula | |
VALUES ( 'x+y*z', 1, 2, 3 ), | |
( '(x+y)*z', 1, 2, 3 ) | |
-- Select_0: 7 | |
-- Select_1: 9 | |
SELECT SQLNET::New(Formula).ValueInt('x', X).ValueInt('y', Y).ValueInt('z', Z).EvalInt() | |
FROM @tableFormula |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- CREATE test table | |
DECLARE @SourceTable TABLE | |
( | |
RowID INT , | |
DelimitedString VARCHAR(8000) | |
) | |
INSERT INTO @SourceTable | |
VALUES ( 1, 'a;a;b' ), | |
( 2, 'c;b;c;b;b;a;c;a' ), |
OlderNewer