尝试将sql查询的结果舍入为2位小数

问题描述 投票:1回答:2

在下面的查询中,我试图返回SUM行的2位小数(.00)的数据:

SELECT
  CONVERT(varchar, YEAR(COALESCE(release_date, requested_date)))
  + RIGHT('00' + CONVERT(varchar, MONTH(COALESCE(release_date, requested_date))), 2) AS yrmnth,
  salesrep,
  customer_name,
  SUM(price_per_ea * COALESCE(open_release_qty, open_order_qty)) AS ext_price
sql sql-server reporting-services ssrs-2016
2个回答
2
投票

您可以使用convert来控制格式

SELECT
CONVERT(VARCHAR, YEAR(COALESCE(release_date, requested_date))) 
    + RIGHT('00' + CONVERT(VARCHAR, 
 MONTH(COALESCE(release_date, requested_date))),2) as yrmnth
,salesrep
,customer_name
,  Convert(decimal(12,2), 
     SUM(price_per_ea * COALESCE(open_release_qty, open_order_qty)))  as ext_price 

0
投票

在您的选择中使用round函数:

round(SUM(price_per_ea * COALESCE(open_release_qty, open_order_qty)),2)
© www.soinside.com 2019 - 2024. All rights reserved.