Implicit conversions
Or ‘How to slow down a query without apparent reason’
I’ve discussed functions in where clauses before and shown how they can prevent index usage and slow down queries. I’ve also discussed data type conversions and shown that SQL Server sometimes does the conversions in places not expected. There’s a nice little gotcha that results from the combination of these two. Let’s take a look at a simple example.
Which of the following queries will run slower? (sample code at the end)
Select ID from TestingConversion where Code = 'AAA' Select ID from TestingConversion where Code = N'AAA'