SQL Eval Function FAQ - Eval SQL.NET
You found a bug when compiling? Report it and it will be fixed, usually within one business day.
All namespace support by SQL CLR are supported by Eval SQL.NET.
- All common namespaces and extension methods can be used without specifying the fullname.
You can see the full list here
Let us know if you believe we missed some.
You are worried about performance? Don't worry, Eval SQL.NET is super-fast and can evaluate over 150,000 expressions in a loop under one second and over 1,000,000 using a table!
Result highly vary depending of your SQL Server performance and expressions to evaluate.
DECLARE @startTime DATETIME, @endTime DATETIME DECLARE @I INT = -1 DECLARE @sqlnet SQLNET = SQLNET::New('i + 1') -- LET Compile the expression to check the compiled performance SET @I = @sqlnet.Val('i', @I).EvalInt() SET @startTime = GETDATE() WHILE @I < 125000 BEGIN SET @I = @sqlnet.ValueInt('i', @I).EvalInt() END SET @endTime = GETDATE() PRINT 'StartTime = ' + CONVERT(VARCHAR(30), @startTime, 121) PRINT 'EndTime = ' + CONVERT(VARCHAR(30), @endTime, 121) PRINT 'Duration = ' + CONVERT(VARCHAR(30), @endTime - @starttime, 114)
SQL CLR allows three types of permissions:
- UNSAFE Eval SQL.NET supports all types and is installed by default with SAFE permissions. Read more about SQL CLR Permissions
This library allows to use parameter, so no SQL Injection is possible!
However, if you build the string to evaluate as you build a dynamic SQL, then there is nothing we can do for you.
Decimal throw an error!
In C#, decimals must be suffixed with "m" to make them valid. By default "1.1" in C# is a double which cannot be added with decimal value.
// Trow exception SELECT SQLNET::New('(x)+1.1234').Val('x', 1.1).Eval() as Result -- SELECT 2.2234 SELECT SQLNET::New('(x)+1.1234m').Val('x', 1.1).Eval() as Result