Traceflag 460 causing truncation errors on code paths that are not followed
This is an odd one. I have tested this on both SQL Server 2017 CU12 and CU13 (in a container and on my production boxes).
If you have an IF/ELSE condition, and you are inserting into a table variable in the ELSE, and that INSERT would cause a truncation issue, it will throw an error, EVEN IF THE CODE IS NOT EXECUTED.
I have attached a reprop script that creates a database called "Repro" and runs the code. When TF460 is enabled, the ELSE block with throw an error when inserting into a table variable, even though it is impossible to even get to the ELSE block, since the IF logic is "IF ( 1= 1)". If you convert the code to a temp table the error goes away, and if you disable TF460 the error goes away.

5 comments
-
Andrew Pruski commented
Fix has been included in CU14. Am currently deploying to our development environment.
Will update
-
Brent Ozar commented
This is bug is still present on SQL 2017 CU13 as of 2019/03/20.
-
Pedro Lopes commented
Thank you for reporting this Mark, we're investigating.
-
Mark Wilkinson commented
This issue does not exist on the latest container image for SQL Server 2019.
-
Mark Wilkinson commented
I forgot to mention, the error you see is the new string truncation error.