We introduced the concept of implicit conversions in Chapter 4, Exploring Query Execution Plans, particularly in the context of the PlanAffectingConvert warnings. An implicit conversion happens when SQL Server needs to compare two values that are not of the same data type. At this point, we should understand how to recognize an implicit conversion in our query plans, but what may not always be obvious is how they got there in the first place and how to correct them.
The most obvious cause of implicit conversions is to compare two columns that are not of the same data type. We can easily avoid this by making sure that columns that are related in our database, and thus may be joined, are of the same data type. A common mistake that can cause this situation is where we have some tables that have been created with NVARCHAR strings and some tables that have...