【发布时间】:2020-04-21 19:17:20
【问题描述】:
我有一个正常运行的查询,我正在合并两个表,删除重复项并将数据保留为最近的生效日期。
表格如下所示:
1.TAX_TABLE---------
tax_id description
1 AZ State
2 AZ-Maricopa Co
4 AZ-Maricopa/Mesa
2.Tax_RATE_TABLE-------
tax_id effective_date tax_percent
1 2015-01-01 00:00:00.000 5.6
2 2015-01-01 00:00:00.000 0.7
4 2015-01-01 00:00:00.000 1.75
4 2019-03-01 00:00:00.000 2
我当前的查询如下所示:
use lhsitedb
select t.tax_id, t.description, tr.effective_date, tr.tax_percent
from dbo.tax t
inner join dbo.tax_rate tr on tr.tax_id = t.tax_id
where tr.effective_date = (
select max(tr1.effective_date)
from dbo.tax_rate tr1
where tr1.tax_id = tr.tax_id
我的输出是这样的,我在 tax_tax 百分比列中得到小数位数。我一直在尝试对该列进行限制,使其仅显示可以放大到百分之一的十进制数字。
注意:此查询在 SSMS 中执行时运行良好,但是,我使用 sqlcmd 并将文件导出到 .txt 文件中,这是产生这些意外结果的位置。
tax_id description effective_date tax_percent
--------------------- ------------------------------- ----------------------- ------------------------
4 AZ-Maricopa/Mesa 2019-03-01 00:00:00.000 2
2 AZ-Maricopa Co 2015-01-01 00:00:00.000 0.69999999999999996
1 AZ State 2015-01-01 00:00:00.000 5.5999999999999996
(17 rows affected)
当那一栏,应该多看几行:
tax_percent
----------------------------
2
1.75
【问题讨论】:
-
tax_percent的数据类型是什么? -
设置为“浮动”。
标签: sql sql-server sql-server-2008