首页 > 解决方案 > T-SQL :: how to remove CONVERT_IMPLICIT

问题描述

Pinal Dave posted a query that we can use to find the most polluting implicit conversion. The query works very well and in fact I found a very polluting one:

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

This horror is:

  1. Taking [Quantité] which has data type MONEY
  2. Taking [Conditionnement] which has data type SMALLINT
  3. Multiplying them together

The table looks like this:

enter image description here

Is there a better way to multiply these two values?

标签: sql-servertsqldatabase-performancequery-performanceimplicit-conversion

解决方案


As @Larnu wrote in the comment:

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.


推荐阅读