chacham
Member
- Local time
- Yesterday, 22:46
- Joined
- Oct 26, 2020
- Messages
- 45
I am using VB to pull some names from a PDF document and write them to the database where they do not yet exist. The query itself is:
The parameters are added and the query prepared. This works.
Now i want to change it to only insert the names when they do not yet exist. If i just add a WHERE clause:
The execution fails with: Query input must contain at least one table or query.
If i change the VALUES() to a SELECT, there is no table and instead the prepare fails with:
System.Data.OleDb.OleDbException: 'Syntax error (missing operator) in query expression '? WHERE NOT EXISTS(SELECT * FROM Staging WHERE Last_Name = ? AND First_Name = ? AND Birthdate = ?)'.'
How do i insert the records only if they do not yet exist?
SQL:
INSERT INTO Staging(Last_Name, First_Name, Birthdate) VALUES(?, ?, ?)
The parameters are added and the query prepared. This works.
Now i want to change it to only insert the names when they do not yet exist. If i just add a WHERE clause:
SQL:
WHERE NOT EXISTS(SELECT * FROM Staging WHERE Last_Name = ? AND First_Name = ? AND Birthdate = ?);
The execution fails with: Query input must contain at least one table or query.
If i change the VALUES() to a SELECT, there is no table and instead the prepare fails with:
System.Data.OleDb.OleDbException: 'Syntax error (missing operator) in query expression '? WHERE NOT EXISTS(SELECT * FROM Staging WHERE Last_Name = ? AND First_Name = ? AND Birthdate = ?)'.'
How do i insert the records only if they do not yet exist?