Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Put array data into a table only if it doesn't exist

Status
Not open for further replies.

jadams0173

Technical User
Joined
Feb 18, 2005
Messages
1,210
I want to put some data from an 2 dim array into a table if it doesn't exist. Here's what I'm doing.

Code:
For x = LBound(aryParentChild, 2) To UBound(aryParentChild, 2)

    conn.Execute "Insert Into tblMy_Parent_Child (Parent,Child) " _
        & "values ('" & aryParentChild(1, x) & "','" & aryParentChild(2, x) & "')", , 129
        
Next x

I'm stuck as to how to check to see that the data does not already exist.

I've tried
Code:
INSERT INTO tblMy_Parent_Child ( Parent, Child )
SELECT '188D5338G1Q375B' AS Expr1, '19D903197G3375A' AS Expr2
WHERE EXPR1<>'188D5338G1Q375B' and expr2<>'19D903197G3375A';
 
the logic would be something like this (not sure the exact syntax for Access):
Code:
run query "SELECT * FROM tableName where all your criteria"

if the result set is empty
  then execute query "INSERT INTO ... where all your criteria"

Leslie

Essential for database developers:
The Fundamentals of Relational Database Design
Understanding SQL Joins
 
If the table is not too large, perhaps you could bring the relevant portion into a recordset and use this recordset to remove any array items before you try to insert?

This would save you the if, and maybe a couple trips to the database.

Just a thought.

Hope this helps,

Alex

[small]----signature below----[/small]
With all due respect, Don Bot, I don't think we should rely on an accident happening. Let's kill him ourselves.

Ignorance of certain subjects is a great part of wisdom
 
Alex,

I had considered that an option as well. I think that is the road I'm going to take. Thanks to both you and Leslie for the responses.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top