I have one table named:
Delegates
This table has four fields:
ID(Auto increment, Primary)
MemberNo, FromYr, ToYr
You can avoid inserting duplicates with this simple, one line of code:
INSERT INTO Delegates (MemNo, FromYr, ToYr) SELECT @MemNo, @FromYr, @ToYr WHERE NOT EXISTS (SELECT 1 FROM Delegates d WHERE d.MemNo=@MemNo AND d.FromYr=@FromYr)
If it's a high load environment where another command could insert the duplicate while this command is executing, you can use the WITH(HOLDLOCK) hint.