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 |
|
edb2003
Yak Posting Veteran
66 Posts |
Posted - 2004-11-08 : 18:21:20
|
Greetings, I have a database that I need to define the return list better than using a GROUP BY. Each month an upload is added to the database. I need to check for duplicate AccountNumbers and Product Descriptions along with DateEntered.ExampleAccountNumber ProductDescription UnitPrice InvoiceDate.12345 Can of Tuna $10.00 4/1/200412345 Can of Tuna $24.00 6/1/2004I had this script as a view in SQL but it grabs dupes in any form or array.SELECT TOP 100 PERCENT AccountNumber, ProductDescription, UnitPrice, InvoiceDateFROM dbo.InvoicesGROUP BY AccountNumber, ProductDescription, UnitPrice, InvoiceDateHAVING (COUNT(*) > 1)ORDER BY AccountNumber DESCCan someone help me right a better script to simply define just the AccountNumber and ProductDescription and not just each field for dupes?I appreciate everyones help :)Happy CodingEdb |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2004-11-08 : 18:24:25
|
| [code]SELECT *FROM dbo.Invoices iINNER JOIN ( SELECT AccountNumber, ProductDescription, COUNT(*) FROM dbo.Invoices GROUP BY AccountNumber, ProductDescription HAVING (COUNT(*) > 1) ) tON i.AccountNumber = t.AccountNumber and i.ProductDescription = t.ProductDescription[/code]Is that what you are looking for?Tara |
 |
|
|
edb2003
Yak Posting Veteran
66 Posts |
Posted - 2004-11-08 : 18:38:10
|
| I was trying to run this but got an error ...No column was specified for column 3 of tIt looks like the COUNT(*) is not being identified. |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2004-11-08 : 18:39:01
|
| [code]SELECT *FROM dbo.Invoices iINNER JOIN ( SELECT AccountNumber, ProductDescription, COUNT(*) AS DupCount FROM dbo.Invoices GROUP BY AccountNumber, ProductDescription HAVING (COUNT(*) > 1) ) tON i.AccountNumber = t.AccountNumber and i.ProductDescription = t.ProductDescription[/code]Tara |
 |
|
|
edb2003
Yak Posting Veteran
66 Posts |
Posted - 2004-11-08 : 18:49:19
|
This is perfect - Thanks Tara. What books do you use to come up with scripts like these? You are very helpful. There should be a tips area. I would make a contribution.Happy Day,Edb |
 |
|
|
robvolk
Most Valuable Yak
15732 Posts |
|
|
|
|
|
|
|