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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 calculated field - Northwind DB query

Author  Topic 

HCindrio
Starting Member

1 Post

Posted - 2011-07-12 : 08:34:47
The query below runs but does not give me what I need. Underlined names are Northwind dbase field names.

I need to show

the unit cost * the quantity, a derived field called subtotal,
the discount, a derived field called discount amount,
and finally a derived field called net price.

I am assuming there is an sql function or vb function I can call to do this but cannot figure it out from the book.

Any help would be appreciated.


Select dbo.Customers.CustomerID, dbo.customers.CompanyName,
dbo.orders.OrderID, dbo.orders.OrderDate,
dbo.[Order Details].Quantity,
dbo.[Order Details].UnitPrice,
dbo.[Order Details].discount,
(dbo.[Order Details].Quantity * dbo.[Order Details].UnitPrice * dbo.[Order Details].Discount) as "Disc. Amount",
dbo.[Order Details].productid
from dbo.Customers
join dbo.Orders
on dbo.customers.CustomerID = dbo.orders.CustomerID
join dbo.[Order Details]
on dbo.orders.OrderID = dbo.[Order Details].OrderID
where dbo.[Order Details].Discount >0
order by dbo.[Order Details].productid asc;
-- Northwind Dbase

   

- Advertisement -