d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Sql Help Please > Just Need To Round To 2 Decimal Places
Add Reply New Topic New Poll
Member
Posts: 16,455
Joined: May 2 2007
Gold: 20.17
Mar 16 2016 11:14pm
so here is my query and results, i need my sales tax and subtotal to round to 2 decimal places


/*------------------------
select OrderID
, ItemID
, cast (price as char (6)) as [Price]
, '$' + cast ((price * .06) as char (7)) as [Sales Tax]
, '$' + cast ((price * .06) + price as char (8)) as [Subtotal]
from ORDER_ITEM
where price >= 20
order by OrderID;
------------------------*/
OrderID ItemID Price Sales Tax Subtotal
----------- ----------- ------ --------- ---------
1004 1004 32.50 $1.9500 $34.4500
1016 1020 47.95 $2.8770 $50.8270
1018 1018 47.50 $2.8500 $50.3500
1019 1017 80.00 $4.8000 $84.8000
1020 1019 30.00 $1.8000 $31.8000
1021 1031 25.99 $1.5594 $27.5494
1031 1029 82.50 $4.9500 $87.4500
1032 1037 85.00 $5.1000 $90.1000
1033 1032 100.00 $6.0000 $106.0000
1035 1038 145.00 $8.7000 $153.7000
1036 1049 20.00 $1.2000 $21.2000
1038 1054 57.50 $3.4500 $60.9500
2001 2000 175.50 $10.5300 $186.0300
2002 2002 125.00 $7.5000 $132.5000
3021 2030 35.00 $2.1000 $37.1000
3022 2031 145.00 $8.7000 $153.7000

(16 row(s) affected)
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Member
Posts: 16,455
Joined: May 2 2007
Gold: 20.17
Mar 17 2016 09:36am
this can be closed, i ended up solving it like this

Code
/*------------------------
SELECT OrderID,
ItemID,
'$' + cast (price as char (10)) as [Price],
'$' + CAST(CAST(ROUND(price * 0.06, 2) AS DECIMAL(18,2)) AS VARCHAR(8)) AS [Sales Tax],
'$' + CAST(CAST(ROUND((price * .06) + price, 2) AS DECIMAL(18,2)) AS VARCHAR(8)) AS [Subtotal]
from ORDER_ITEM
where price >= 20
order by OrderID;
------------------------*/
OrderID ItemID Price Sales Tax Subtotal
----------- ----------- ----------- --------- ---------
1004 1004 $32.50 $1.95 $34.45
1016 1020 $47.95 $2.88 $50.83
1018 1018 $47.50 $2.85 $50.35
1019 1017 $80.00 $4.80 $84.80
1020 1019 $30.00 $1.80 $31.80
1021 1031 $25.99 $1.56 $27.55
1031 1029 $82.50 $4.95 $87.45
1032 1037 $85.00 $5.10 $90.10
1033 1032 $100.00 $6.00 $106.00
1035 1038 $145.00 $8.70 $153.70
1036 1049 $20.00 $1.20 $21.20
1038 1054 $57.50 $3.45 $60.95
2001 2000 $175.50 $10.53 $186.03
2002 2002 $125.00 $7.50 $132.50
3021 2030 $35.00 $2.10 $37.10
3022 2031 $145.00 $8.70 $153.70

(16 row(s) affected)


This post was edited by Drakwen on Mar 17 2016 09:37am
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll