SQL Round查询

时间:2017-03-22 05:13:23

标签: sql sql-server rounding

在SQL中尝试将销售税和小计舍入到我的查询的两位小数。 这是我的问题。

    select OrderID
    , ItemID
    , '$' + cast(price as varchar (7)) as [Price] 
    , (price) * 0.06 as [Sales Tax] 
    , (price) * 0.06 + (price) as [Subtotal]

    from ORDER_ITEM
    where price >= (20)

由于

2 个答案:

答案 0 :(得分:2)

select OrderID
    , ItemID
    , '$' + cast(price as varchar (7)) as [Price] 
    ,convert(decimal(18,2), (price) * 0.06) as [Sales Tax] 
    , convert(decimal(18,2),(price) * 0.06 + (price)) as [Subtotal]

    from ORDER_ITEM
    where price >= (20)

答案 1 :(得分:0)

   -- You Can Use ROUND Function to Round Up The Column you want.   
       select OrderID
            , ItemID
            , '$' + cast(price as varchar (7)) as [Price] 
            , ROUND((price) * 0.06,2) as [Sales Tax] 
            , ROUND((price) * 0.06 + (price),2) as [Subtotal]

            from ORDER_ITEM
            where price >= (20)