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.
| Author |
Topic |
|
touandcim
Starting Member
4 Posts |
Posted - 2010-02-11 : 19:30:13
|
| I'm a beginning SQL Server student and need help returning the correct values. What I need to do is return 4 columns: VendorName, InvoiceNumber, InvoiceDate, InvoiceTotal. It also needs to return only the earliest InvoiceDate for each vendor (meaning one InvoiceDate per vendor). This is my code. I know it is overly complicated and it doesn't even work right! Any hints or suggestions would be super helpful!Select VendorName, InvoiceNumber, InvoiceDate, InvoiceTotalFrom Invoices Join VendorsOn Invoices.VendorID = Vendors.VendorIDWhere InvoiceDate In (Select MIN(Distinct InvoiceDate) From Invoices Group By VendorID Having VendorID In (Select Distinct VendorID From Invoices)) |
|
|
Sachin.Nand
2937 Posts |
Posted - 2010-02-11 : 23:06:09
|
| Which version of SQL server are you using?SQL 2000 or SQL 2005.PBUH |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-02-12 : 01:10:39
|
| [code]Select v.VendorName, i.InvoiceNumber, i.InvoiceDate, i.InvoiceTotalFrom Invoices i Join Vendors vOn Invoices.VendorID = Vendors.VendorIDWhere InvoiceDate = (Select MIN(InvoiceDate) FROM Invoices WHERE VendorID = i.VendorID )[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|