sql-server - 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:
- Taking [Quantité] which has data type
MONEY
- Taking [Conditionnement] which has data type
SMALLINT
- Multiplying them together
The table looks like this:
Is there a better way to multiply these two values?
解决方案
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.
推荐阅读
- c++ - 编译器 Baremetal (arm-none-eabi) - 编译器实现
- python - 如何将文件上传到 Azure Blob 存储?
- nosql - 复合索引(带数组索引)与复合索引和沙发库 N1QL 中的单独数组索引
- r - 将包含每小时时间序列的数据帧转换为 r 中的 ts 对象
- android - Firebase 依赖项在运行时创建错误
- listview - 在列表视图中更改文本按钮的文本
- scala - 如何从地图中检索派生类?
- angular - 根据Angular中的文本突出显示文本
- r - TimeSplitter:评估错误(替代(退出)、数据、父框架()):找不到对象“年龄”
- php - 为什么我不能从 jquery 向 laravel 路由发出请求?