2017-03-22 21 views
0

嘗試將SQL查詢中的銷售稅和小計到小數點後兩位。 這是我的查詢。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
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) 
+0

正是我一直在尋找。謝謝 –

+0

如果它適合你,請接受我的回答。 –

+0

我確實做過。我是新來的S/O,所以我的選票只有在聲望達到15時纔算。 –

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)