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

Using a SELECT in an INSERT query

bard777
P: 23
I have a form kicking off an INSERT query. I need to check another table for a matching value and use a field from that table as the value for one of the fields in my insert.

Table 1 (insert from form)

PLN_NUM
SLN_NUM

Table 2

PLN_NUM
SLN_NUM

I need to do something like:
Expand|Select|Wrap|Line Numbers
  1. INSERT INTO [Table 1] (PLN_NUM, SLN_NUM) VALUES (fld_PLN_NUM, (SELECT SLN_NUM FROM [Table 2] WHERE PLN_NUM = fld_PLN_NUM))
Can somebody help with how to make this insert?

Thanks
Jul 31 '08 #1
Share this Question
Share on Google+
2 Replies


bard777
P: 23
I got it to work using the following:
Expand|Select|Wrap|Line Numbers
  1. INSERT INTO Table 1 (PLN_NUM, SLN_NUM)
  2. SELECT fld_pln_num, SLN_NUM
  3. FROM [Table 2]
  4. WHERE [Table 2].PLN_NUM = fld_pln_num
fld_pln_num represents a textbox on the form that executes the insert.
Jul 31 '08 #2

NeoPa
Expert Mod 15k+
P: 31,186
Thanks for posting your solution. It even makes the question clearer.
Aug 5 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.