<p>Do you know a way to organize boolean expressions in a database while allowing infinite nesting of the expressions?</p>

<p>Example:</p>

<pre><code>a = 1 AND (b = 1 OR b = 2)
</code></pre>

<p>The expression as a whole shouldn't be stored as varchar to preserve data integrity.</p>

An expression is a treelike structure. So you need a way to present the tree in a table.
You can for example use the fields:
ID
TypeExpression (and, or etc...)
FirstChildID
SecondChildID
In this case, you have the following types:
AND, Children point to other expression.
OR, Children point to other expression.
Equal, Children point to other expression.
Literal, FirstChild points to an entry in a literal table.
VariableLookup, FirstChild points to an entry in a varable table.
But I think there are better ways to organise expression. I once made a simple expression evaluator that accepts a string and produces a numeric result.