在下面的查询中,我试图返回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
您可以使用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
在您的选择中使用round函数:
round(SUM(price_per_ea * COALESCE(open_release_qty, open_order_qty)),2)