I have confusion on how to prevent duplicate InvoiceNo
against CompanyId
. I just have prepare an Invoice project that has field like CompanyId
and InvNo
. Both do not have Unique Keys because Company ID and InvoiceNo both have to repeated. as per below
CompanyID InvNo
1 1
2 1
1 2
3 1
4 1
1 3
Now I want to fire a raiserror on duplicate InvoiceNo against a particular CompanyId. How do I implement this. Important: if i create a unique index then duplicate records will not be allowed and it is important to allow except against particular CompanyId