Skip to content

Instantly share code, notes, and snippets.

DECLARE @sqlnet SQLNET = SQLNET::New('Regex.Split(input, "/")')
SELECT *
FROM SourceTable
CROSS APPLY dbo.SQLNET_EvalTVF_1(@sqlnet.ValueString('input', DelimitedString))
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()')
// using Z.EntityFramework.Plus; // Don't forget to include this.
var ctx = new EntitiesContext();
// Cache queries with related tags
var states = ctx.States.FromCache("countries", "states");
var stateCount = ctx.States.DeferredCount().FromCache("countries", "states", "stats");
// Expire all cache entries using the "countries" tag
QueryCacheManager.ExpireTag("countries");
// 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();
// 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();
-- 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 *
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;
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")')
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
-- 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' ),