2

I need to build a check on staged data (in various tables). The data field values will have to be checked against (business) rules that evaluate to a boolean. Users can define these rules with logic expressions:

A > B, A > AND A < C, A > B OR A < C, A = B OR A = C, etc. (where A,B,C resprent field values).

The rules will be in a table as strings together with the column a rule applies to. I've worked out how to get field values in the rule and how to apply the rules against the staged data. (I also use RegEx to test against -custom- datatypes. I turn the stage into a EAV-like table and join will the rules on the columnnames.)

I'm not a .Net programmer, so building a parser and evaluator is not possible for me. I'm looking for a (save) solution to evaluate logic/boolean expressions runtime. I plan to put the evaluator in a CLR and use it as a function (like I did with RegEx). I've looked at NCALC (unsafe), Flee (outdated), etc., but I can't find a up to date solution for evaluating these expressions. (Parsing the string to a SQL-expression like IFF, IF, CASE, seems a bit out of the way.)

Any suggestions. I'm probably missing some obvious thing here.

MacMesser
  • 55
  • 4

1 Answers1

0

Disclaimer: I'm the owner of the project Eval SQL.NET

Eval SQL.NET allow to evaluate boolean expression using parameter directly in T-SQL if the syntax is compatible with C#,

Example

-- SELECT 1 (true)
SELECT  SQLNET::New('A > B && B < C')
.Val('A', 3)
.Val('B', 1)
.Val('C', 2).EvalBit()

-- SELECT 0 (false)
SELECT  SQLNET::New('A > B && B < C')
.Val('A', 3)
.Val('B', 2)
.Val('C', 1).EvalBit()
Jonathan Magnan
  • 10,874
  • 2
  • 38
  • 60