Evaluate logical expressions in an SQL row column

I have a table containing id columns (int), boolean expression (varchar) and result (bit). The boolean expression is stored in varchar, which I need to evaluate and put the result in the result column . For example, a column may contain:

'1=1'
'2<3 AND 1^1=1'
'3>4 OR 4<2'

Then the result column should contain

1
0
0

I am currently using a cursor to navigate rows and using dynamic sql to evaluate an expression.

"IF(" + @expression + ") SET @result = 1" 

Is there a better, more efficient way to do this? I would ideally want to get rid of the cursor. Any ideas? Would it be better done using assembly?

+3
source share
2 answers

CLR.

:

infact, ( ):

SELECT dbo.eval('1=1' )
SELECT dbo.eval('3>4 OR 4<2' )

, ^ (caret) - CLR XOR.

+2

SQL, infix, 1 + 2 + 3 + 4/(5-2). . , . Sequence0_8000, , .

+1

All Articles