2017-03-22 2 views
0

Der Versuch, Umsatzsteuer und Zwischensumme auf zwei Dezimalstellen für meine Abfrage in SQL zu runden. Hier ist meine Abfrage.SQL Runde Abfrage

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) 

Dank

Antwort

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

Genau das, was ich suchte. Danke –

+0

Wenn es für dich funktioniert, akzeptiere bitte meine Antwort. –

+0

tat ich eigentlich. Ich bin neu bei S/O, also zählt meine Stimme erst, wenn ich einen Ruf von 15 erreicht habe. –

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)