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
 Distinct VendorID?!

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, InvoiceTotal
From Invoices Join Vendors
On Invoices.VendorID = Vendors.VendorID
Where 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
Go to Top of Page

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.InvoiceTotal
From Invoices i Join Vendors v
On Invoices.VendorID = Vendors.VendorID
Where InvoiceDate = (Select MIN(InvoiceDate)
FROM Invoices
WHERE VendorID = i.VendorID )
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -