Sql Server- My query: select OrderID, ItemID, \'$\' + cast(price as varchar(10))
ID: 3730390 • Letter: S
Question
Sql Server-
My query:
select OrderID, ItemID, '$' + cast(price as varchar(10)), '$' + cast(price * .06 as varchar(10)) as [Sales Tax], '$' + cast(price * 1.06 as varchar(10)) as [Sub Total]
from ORDER_ITEM
My results:
OrderID ItemID Sales Tax Sub Total
----------- ----------- ----------- ----------- -----------
1004 1003 $15.50 $0.9300 $16.4300
1036 1046 $15.00 $0.9000 $15.9000
1036 1049 $20.00 $1.2000 $21.2000
How do I round the sales Tax and Subtotal Columns? I have tried to use the decimal instead of varchar and it will not allow the '$' then.
Explanation / Answer
CREATE TABLE ORDER_ITEM (
OrderID int,
ItemID int,
price decimal(4,2)
);
INSERT INTO ORDER_ITEM(OrderID,ItemID,price) VALUES (1004,1003,'15.50');
INSERT INTO ORDER_ITEM(OrderID,ItemID,price) VALUES (1036,1046,'15.00');
INSERT INTO ORDER_ITEM(OrderID,ItemID,price) VALUES (1036,1049,'20.00');
select OrderID,ItemID, '$' + convert(varchar,price) , '$' +convert( varchar,cast(price * .06 as decimal(4,2))) as [SalesTax], '$' + convert( varchar,cast(price * 1.06 as decimal(4,2))) as [Sub Total] from ORDER_ITEM
RESULT:
OrderID
ItemID
(No column name)
SalesTax
Sub Total
1
1004
1003
$15.50
$0.93
$16.43
2
1036
1046
$15.00
$0.90
$15.90
3
1036
1049
$20.00
$1.20
$21.20
OrderID
ItemID
(No column name)
SalesTax
Sub Total
1
1004
1003
$15.50
$0.93
$16.43
2
1036
1046
$15.00
$0.90
$15.90
3
1036
1049
$20.00
$1.20
$21.20
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.