Parth Patel
Parth Patel

Reputation: 258

SQL: Check AND/OR string with IF clause

Check '(1=1 AND (1=1 OR 1=1) OR 0=1)' string return true or false

if (1=1 AND (1=1 OR 1=1) OR 0=1)
print '1'
else
print '0'

if i check like this then it returns perfect value but if i have string variable containing value '(1=1 AND (1=1 OR 1=1) OR 0=1)' and then how to check with if clause??

Upvotes: 1

Views: 65

Answers (1)

Matten
Matten

Reputation: 17631

You can build up a dynamic query:

declare @conditionString nvarchar(max)
set @conditionString = '(1=1 AND (1=1 OR 1=1) OR 0=1)'

declare @sql nvarchar(max)
set @sql = 'if ' + @conditionString + '
              print ''1''
            else 
              print ''0'''

sp_executeSql @sql

Upvotes: 1

Related Questions