T-SQL :: 如何删除 CONVERT_IMPLICIT

T-SQL :: how to remove CONVERT_IMPLICIT

Pinal Dave 发布了一个 query,我们可以用它来找到污染最严重的隐式转换。该查询运行良好,事实上我发现了一个非常污染的查询:

SUM(-[Quantité] * [Conditionnement]) AS QteVendueUQB,

这个恐怖是:

  1. 采用数据类型为 MONEY
  2. 的 [Quantité]
  3. 采用数据类型为 SMALLINT
  4. 的 [Conditionnement]
  5. 将它们相乘

table 看起来像这样:

是否有更好的方法将这两个值相乘?

正如@Larnu 在评论中所写:

If the data types are different, then one of them will be implicitly converted using data type precedence. There is no way round that. It is by design, and intended. If you don't want implicit conversion, don't use different data types for data that will interact with each other.