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
CREATE FUNCTION [dbo].[fn_Split]( | |
@sInputList VARCHAR(8000), | |
@sDelimiter VARCHAR(8000) = ',' | |
) | |
RETURNS @List TABLE ( item VARCHAR(8000) ) | |
BEGIN | |
DECLARE @sItem VARCHAR(8000) | |
WHILE CHARINDEX(@sDelimiter, @sInputList, 0) <> 0 | |
BEGIN |
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
// Example from Entity Framework Extensions Library | |
// BulkInsert extension methods added automatically | |
using (var ctx = new EntitiesContext()) | |
{ | |
// Do not use the ChangeTracker or require to add the list in the DbSet | |
ctx.BulkInsert(list); | |
} |
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
// 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
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
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
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; |
OlderNewer