How to evaluate string expression in SQL Server?

For a string '100+200', how to evaluate it?

I want to get 300the output.

-6
source share
2 answers
DECLARE @expression VARCHAR(MAX) = '100+200'
EXEC    (N'SELECT ' + @expression)

If it comes from the user, make sure that it clears

+2
source

Seriously? How about this:

SELECT 100 + 200;
+1
source

Source: https://habr.com/ru/post/1680655/


All Articles