I'm having a problem when migrating from SQL Server 2008 R2 to SQL Server 2019. My code
DECLARE @str NVARCHAR(50) = 'all',
@int TINYINT = 1
DECLARE @tmp TABLE (val nvarchar(MAX))
INSERT INTO @tmp VALUES('123')
INSERT INTO @tmp VALUES('all')
SELECT val
FROM @tmp
WHERE @str = 'ALL' OR @int = val
When using SQL Server 2008 R2, it's fine. The output as expected like below
val
123
all
However, when I migrate to SQL Server 2019, the error like below occurs. Besides, it just happens unusually in 2019.
Msg 245 Level 16 State 1 Line 8 Conversion failed when converting the nvarchar value 'all' to data type int.
As you can see, the second condition OR @int = val
happened unexpectedly.
I was wondering if it fails due to any breaking changes related to the order of OR
operator or case sensitive
ALL
vs all
in the next SQL Server 2008 R2 version.
Updated
Sorry for my reproduce code make you guys confuse. This is my original code