January 30, 2011 at 1:48 am
Hi below returns a list of unique products (type purchased, purchased assembly) that have been purchased and invoiced.
SELECT DISTINCT pii.Product
FROM PurchaseInvoiceItems AS pii
WHERE pii.Product IN (SELECT p.Product FROM Products AS p WHERE p.Type IN ('B','P'))
The above returns 3000 rows.
I would like to list the last purchase price of the unique product. PurchaseInvoiceItems is related to PurchaseInvoices by PurchaseInvoice. PurchaseInvoices has field 'AccountingDate'. PurchaseInvoiceItems has a field 'ItemValue'.
Kind Regards,
Phil.
-------------------------------------------------------------------------------------
A neutron walks into a bar. "I'd like a beer" he says. The bartender promptly serves up a beer. "How much will that be?" asks the neutron. "For you?" replies the bartender, "no charge."
Two hydrogen atoms walk into a bar. One says, 'I think I've lost an electron.' The other says 'Are you sure?' The first says, 'Yes, I'm positive... '
Tommy Cooper
January 30, 2011 at 2:55 am
I think you've been around long enoug to know how it works...
Table DDL, sample data and expected results, please.
January 30, 2011 at 3:01 am
Fair point, working on it 🙂
Phil.
-------------------------------------------------------------------------------------
A neutron walks into a bar. "I'd like a beer" he says. The bartender promptly serves up a beer. "How much will that be?" asks the neutron. "For you?" replies the bartender, "no charge."
Two hydrogen atoms walk into a bar. One says, 'I think I've lost an electron.' The other says 'Are you sure?' The first says, 'Yes, I'm positive... '
Tommy Cooper
January 30, 2011 at 3:22 am
Take a look at this article that i wrote a little while back.
http://www.sqlservercentral.com/articles/T-SQL/71571/
You just need top(1).
January 30, 2011 at 6:12 am
Update: Code removed.
Thanks to all those that took time to review.
Phil.
-------------------------------------------------------------------------------------
A neutron walks into a bar. "I'd like a beer" he says. The bartender promptly serves up a beer. "How much will that be?" asks the neutron. "For you?" replies the bartender, "no charge."
Two hydrogen atoms walk into a bar. One says, 'I think I've lost an electron.' The other says 'Are you sure?' The first says, 'Yes, I'm positive... '
Tommy Cooper
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply