By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,987 Members | 967 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,987 IT Pros & Developers. It's quick & easy.

Insert only if item doesn't already exist... easy right?

P: n/a
Good morning all and thanks for taking the time to read this.

So I have this recursive function that finds child parts from a master
parent parts list. Currently I'm using

sqlcmd2 = "INSERT INTO tblAllParts(PartNumAfterMPL) VALUES (" & _
"'" & rs2!ID_ITEM_CHILD & "')

Is there a way that I can only insert this value if the
rs2!ID_ITEM_CHILD does not already exist in
[tblAllParts].PartNumAfterMPL ??

Thanks for the help,
Derek

Nov 13 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
rkc
pointBoarder wrote:
Good morning all and thanks for taking the time to read this.

So I have this recursive function that finds child parts from a master
parent parts list. Currently I'm using

sqlcmd2 = "INSERT INTO tblAllParts(PartNumAfterMPL) VALUES (" & _
"'" & rs2!ID_ITEM_CHILD & "')

Is there a way that I can only insert this value if the
rs2!ID_ITEM_CHILD does not already exist in
[tblAllParts].PartNumAfterMPL ??


The only way that works under all circumstances is to create
an index on the field and allow no duplicates in the design
of the table.
Nov 13 '05 #2

P: n/a
untested

sqlcmd2 = "INSERT INTO tblAllParts(PartNumAfterMPL) VALUES (" & _
"'" & rs2!ID_ITEM_CHILD & "') & "where '" &
rs2!ID_ITEM_CHILD & "' NOT IN (SELECT partNumAfterMpl from
tblAllParts)"

Nov 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.