Hi All,
I have a invoice's table and am trying to write a script looking for duplicate invoice numbers. The catch is the same invoice number can be used by different suppliers within the same receiving company.
This is what I have so far;
select distinct invoicenumber,count(invoicenumber)
from [xxx].[dbo].[invoice_head]
group by invoicenumber having count(invoicenumber) > 1
sample return;
ID date supplier invoiceid companyid amount
2221 12/2/11 jones pty 0002 41 $250
3212 13/4/11 acme pty 0002 41 $110
5454 01/01/11 maccas 0002 41 $500
I was thinking of trying a 'where' it is not equal to itself(the company id is not the same) so it would return the count only if the company is is different.
But not sure what to do next, maybe join the supplier to the supplier table?
Thanks
I have a invoice's table and am trying to write a script looking for duplicate invoice numbers. The catch is the same invoice number can be used by different suppliers within the same receiving company.
This is what I have so far;
select distinct invoicenumber,count(invoicenumber)
from [xxx].[dbo].[invoice_head]
group by invoicenumber having count(invoicenumber) > 1
sample return;
ID date supplier invoiceid companyid amount
2221 12/2/11 jones pty 0002 41 $250
3212 13/4/11 acme pty 0002 41 $110
5454 01/01/11 maccas 0002 41 $500
I was thinking of trying a 'where' it is not equal to itself(the company id is not the same) so it would return the count only if the company is is different.
But not sure what to do next, maybe join the supplier to the supplier table?
Thanks