I have a table with a column called PtObjId of the INT data type.
From my understanding by looking at the thread located Microsoft Documentation here. I can only store up to values that are +/- 2,147,483,647
If I run this query:
Select top 100 *
from [table]
where [PtObjId] IN (44237141916)
Shouldn't it error out?
Why does this query error out below:
select top 100 *
from [table]
where [PtObjID] IN ('44237141916')
but the top query doesn't error out?
This sqlshack-article explains details about implicit conversions in SQL-Server.
One value must implicitly be cast for the comparison. The literal
44237141916is treated asdecimal, which has a higher precedence thanint, so the other operand is cast todecimal.A full list of precedences (and a table of possible conversions) are given in the article, an extract:
(lower number = higher precedence)
In the case of
intandnvarchar, the one with higher precedence isint, and this leads to an overflow for 44237141916.