Free Libraries

Online Help

SQL Server Eval

Introduction

How to evaluate an arithmetic expression in SQL Server is a common subject. There are several reasons why an “Eval” function like JavaScript could be useful in SQL such as evaluating custom report field for a trusted user.

Multiple partial solutions exists like using “EXEC(Transact-SQL)” which is limited, cannot be used inside SELECT statement and lead to SQL Injection or using an homemade function which, most of time, fail at supporting simple operator priority and parenthesis.

SQL Eval.NET is a complete solution which, not only lets you evaluate dynamic arithmetic expression, but lets you use the full C# language directly in T-SQL stored procedures, functions and triggers.

Solution

Evaluating an expression is very fast and scalable. You can see performance 3-20x faster than User-Defined Function (UDF) and you can evaluate an expression as much as ONE MILLION times under a second.