Hello and thank you @SSCrazy Eights,
I would like to see if SQL has the same problem as Python.
In Python if you declare '@a' and '@b' as two variables of value '100' and you compare them you have a TRUE. But if you compare the same two variable with value '1000' you will have a FALSE.
I't crazy, right?
This because Python has some cache logic that goes up till a certain numeric limit and then it just returns you a false.
I'm trying to archive the same with SQL and I would like to test a few data type so I changed your code to this:DECLARE @a numeric set @a = 100
DECLARE @b-2 numeric set @b-2 = 100
DECLARE
@strBoolean NVARCHAR(1000),
@strSQL NVARCHAR(1000),
@bResult BIT = 0
SET @strBoolean = N'('@a'='@b' AND ('@a'='@b' OR '@a'='@b'))' --returns 1
--SET @strBoolean = N'(1=2 AND (1=1 OR 2=2))' --returns 0
SET @strSQL = N'SELECT @bCheck = 1 WHERE '+@strBoolean
EXEC sp_executesql @strSQL, N'@bCheck INT OUT', @bResult OUT
SELECT
(CASE @bResult
WHEN 1 THEN 'True'
ELSE 'False'
END) result
but SSMS returns me a:
Msg 102, Level 15, State 1, Line 9
Incorrect syntax near '@a'.
Is there a way to execute the variables inside the "SET @strBoolean"?
Thank you