Link to home
Start Free TrialLog in
Avatar of Stefan Motz
Stefan MotzFlag for United States of America

asked on

Prevent inserting duplicate values in SQL Server database

Hi Experts,
I'm using the following code to insert values in my table:
INSERT INTO OT_Table (OT_Line, Emp_Id, Timestamp) VALUES ('"& strOT_Line &"','"& strEmp_Id &"','"& strTimeStamp &"')

Open in new window

I would like to prevent insertion if the OT_Line and Emp_Id are the same.
In that case I would just like to update the value of the TimeStamp field.

How can I accomplish that on my classic ASP page?
Thank you for your help
ASKER CERTIFIED SOLUTION
Avatar of Daniel Van Der Werken
Daniel Van Der Werken
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Stefan Motz

ASKER

Thank you very much; it's working now. This is classic ASP so I've used the following code:

IF NOT EXISTS(SELECT * FROM OTEWR WHERE OT_Line = '"& strOT_Line &"' AND Emp_Id  = '"& strEmp_Id &"' ) BEGIN INSERT INTO OTEWR(OT_Line, Emp_Id, PersonAddedOn) VALUES ('"& strOT_Line &"', '"& strEmp_Id &"', '"& strPersonAddedOn &"') END