Hello,

I am fairly new to this forum and to TSQL although have done alot of SQL scripting.

I wondered if someone could help me with a stored proceedure I am putting together.

I am trying to count the number of invoice number that are duplicated within the database across the company. However an Invoice number is generated using a statement from two different tables.

I have read up on TSQL and can run using a count from one table only.

Can anyone point me in the right direction? or direct me to some useful websites?

Thanks

SQL Script
-----------
SELECT IIf([dbo_oas_docline]![doccode]="Pmigrate",[dbo_oas_dochead]![descr],[ref1]) AS A, Count(IIf([dbo_oas_docline]![doccode]="Pmigrate",[dbo_oas_dochead]![descr],[ref1])) AS B
FROM dbo_oas_docline INNER JOIN dbo_oas_dochead ON (dbo_oas_docline.docnum = dbo_oas_dochead.docnum) AND (dbo_oas_docline.doccode = dbo_oas_dochead.doccode) AND (dbo_oas_docline.cmpcode = dbo_oas_dochead.cmpcode)
WHERE ((([A]=[B])>1))
GROUP BY IIf([dbo_oas_docline]![doccode]="Pmigrate",[dbo_oas_dochead]![descr],[ref1]);