Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 calculation for totals using percentages

Author  Topic 

oraclelady
Starting Member

1 Post

Posted - 2006-01-25 : 15:07:40
I am trying to figure how write sql statement that will give the total cost.

unit price * quantity - discount = total cost

Unit price = 9.8
quantity = 30
discount = 0.15

Srinika
Master Smack Fu Yak Hacker

1378 Posts

Posted - 2006-01-25 : 16:34:31
U want that to be done in MS SQL Server?
and since u gave only one set of data, I think best way to use a calculator
Or if u want u can do something like following ;
-- of course u may need to define the variables first
Set @Unitprice = 9.8
Set @quantity = 30
Set @discount = 0.15
Print (@Unitprice * @quantity ) * (1 - @discount )

OR

If u want to do this for a table / fields - u should have given the table & field names along with some sample data & expected results
Go to Top of Page

Frank Kalis
Constraint Violating Yak Guru

413 Posts

Posted - 2006-01-26 : 03:26:03
Looks like an example straight from the Northwind database

SELECT UnitPrice * Quantity * (1 - Discount) AS "Total Cost"
FROM [Order Details]


--
Frank Kalis
Microsoft SQL Server MVP
http://www.insidesql.de
Heute schon gebloggt? http://www.insidesql.de/blogs
Go to Top of Page
   

- Advertisement -