Michael Fogarty
Michael Fogarty

Reputation: 301

SQL Round query

Trying to round sales tax and subtotal to two decimal places for my query in SQL. Here's my query.

    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)

Thanks

Upvotes: 0

Views: 278

Answers (2)

Alfaiz Ahmed
Alfaiz Ahmed

Reputation: 1728

   -- 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)

Upvotes: 0

Ramesh Kharbuja
Ramesh Kharbuja

Reputation: 407

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)

Upvotes: 2

Related Questions