christer99
IS-IT--Management
- Dec 3, 2001
- 247
This insert statement keeps inserting data although there is already an identical record.
If Not Exists(SELECT * From dbo.Contact Where (ACCREC='"&recval&"') and (FIRSTNAME='"&tmfirstname&"') and (LASTNAME='"&tmfirstname&"')) INSERT INTO dbo.CONTACT (ACCREC,FIRSTNAME,LASTNAME,CONTACTEMAIL,WORKPHONE) VALUES ('"&recval&"','"& tmfirstname&"','"&tmlastname&"','"&emailaddress&"','"&phonenumdigits&"')
It does work when I change to only check for the ACCREC (and not the name) and if I change the select statement to select 1, but it doesn't work once I added the FIRSTNAME and the LASTNAME to the criteria. The same ACCREC can have multiple people, and thus only checking for the ACCREC is no good. I appreciate if anyone has the answer to this problem.
If Not Exists(SELECT * From dbo.Contact Where (ACCREC='"&recval&"') and (FIRSTNAME='"&tmfirstname&"') and (LASTNAME='"&tmfirstname&"')) INSERT INTO dbo.CONTACT (ACCREC,FIRSTNAME,LASTNAME,CONTACTEMAIL,WORKPHONE) VALUES ('"&recval&"','"& tmfirstname&"','"&tmlastname&"','"&emailaddress&"','"&phonenumdigits&"')
It does work when I change to only check for the ACCREC (and not the name) and if I change the select statement to select 1, but it doesn't work once I added the FIRSTNAME and the LASTNAME to the criteria. The same ACCREC can have multiple people, and thus only checking for the ACCREC is no good. I appreciate if anyone has the answer to this problem.