O'Reilly logo
  • Dustin Waybright thinks this is interesting:

WHERE propertytype = 'INT' AND CAST(propertyval AS INT) > 10

Suppose that the table being queried holds different property values. The propertytype column represents the type of the property (an INT, a DATE, and so on), and the propertyval column holds the value in a character string. When propertytype is ‘INT’, the value in propertyval is convertible to INT; otherwise, not necessarily.


Cover of Training Kit (Exam 70-461): Querying Microsoft® SQL Server® 2012


Make sure not to assume that predicates are evaluated left to right. SQL Server could choose to evaluate the second predicate first and ignore the first predicate where the second predicate is false. This could impact the query result.