This topic is locked
[SOLVED]

 Before Insert On Import

6/14/2013 2:50:42 PM
ASPRunnerPro General questions
lefty author

Asprunner 7.2
I am trying to import records from xls file and avoid inserting on import, records that are duplicate for two fields . I have the following code below.
strSQLExists = "select * from Customers Where CustomerID IN (Select CustomerID from Customers where CustomerID = " & values("CustomerID") & ") And EmployeeID IN (Select EmployeeID from Customers where EmployeeID =' " & values("EmployeeID") & "') "
set rsExists = CreateObject("ADODB.Recordset")

rsExists.Open strSQLExists, dbConnection
if not rsExists.eof then

' if record exists do something
BeforeInsert = false
else
' if dont exist do something else

BeforeInsert = True
I have tested this and it still imports duplicate records from import file where there is a CustomerID and EmployeeID record already in Customer table. Any help appreciated . Have tried using raw values but get same result.

CustomerID is Numeric and EmployeeID is text.

Sergey Kornilov admin 6/14/2013

John,
you need to create a small test import file and print those SQL queries on the page instead of executing them. Then run those queries against your database to make sure correct results are returned.
To print SQL Query on the page use:

Response.Write strSQLExists & "
"
lefty author 6/14/2013

IT was the space between ' " on left because of text field . I did not realize it counted white space in vbscript there.
where EmployeeID =' <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=71179&image=1&table=forumreplies' class='bbcemoticon' alt='<<' /> " & values("EmployeeID") & "') "