![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
#3
| |||
| |||
|
#4
| |||
| |||
|
|
SELECT DISTINCT TOP 2 * FROM @t |
#5
| |||
| |||
|
|
I have a POITEM Table which has just three columns InvetoryID, DateofOrder, VendorID I have under the same InventoryID ,multiple DateofOrders and VendorrID;s. SO for eg here is a couple of lines of the data, InvetoryID, DateofOrder, VendorID ACCKAPCONS01 05/05/2005 ALTPRO001 ACCKAPCONS01 04/03/2005 ALTPRO001 ACCKAPCONS02 04/02/2005 TRAP00001 ACCKAPCONS02 04/01/2005 ALTPRO001 What I am trying to do is basically get the last 2 vendors from whom we bought the Inventory item. In some cases we would have just bought it from one vendor and in some cases we might have bought it from different vendors at different times. ( As e.g above) What query can I run that will tell me the last two vendors (if last 2 are the same it should look for the next order with a different vendorID and keep going till it finds a different Vendor ID if it exists) Thanks so much for your assistance. S Commar |
#6
| |||
| |||
|
|
get the last 2 vendors from whom we bought the Inventory item. |
|
= (SELECT MAX(order_date) FROM Foobar AS F2 |
|
(SELECT MAX(order_date) FROM Foobar AS F3 |
#7
| |||
| |||
|
|
I have a POITEM Table which has just three columns InvetoryID, DateofOrder, VendorID I have under the same InventoryID ,multiple DateofOrders and VendorrID;s. SO for eg here is a couple of lines of the data, InvetoryID, DateofOrder, VendorID ACCKAPCONS01 05/05/2005 ALTPRO001 ACCKAPCONS01 04/03/2005 ALTPRO001 ACCKAPCONS02 04/02/2005 TRAP00001 ACCKAPCONS02 04/01/2005 ALTPRO001 What I am trying to do is basically get the last 2 vendors from whom we bought the Inventory item. In some cases we would have just bought it from one vendor and in some cases we might have bought it from different vendors at different times. ( As e.g above) What query can I run that will tell me the last two vendors (if last 2 are the same it should look for the next order with a different vendorID and keep going till it finds a different Vendor ID if it exists) Thanks so much for your assistance. S Commar |
![]() |
| Thread Tools | |
| Display Modes | |
| |