Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

insert sql using both VALUES and SUB-QUERY

Posted on 2013-12-14
5
Medium Priority
?
362 Views
Last Modified: 2013-12-15
hi guys,

i can write an insert query and use VALUES to insert the data i want. i can also use a subquery to insert the data. can i use a mixture of 2 or must i write 2 queries?

e.g. join the 2 lines of code into 1

Sub InsertQuery_UsingValuesOnly()
    Call CurrentDb.Execute("INSERT INTO DestinationTable (TableField1, TableField2) VALUES (""something1"", ""something2"");")
End Sub
Sub InsertQuery_UsingSQLOnly()
    Call CurrentDb.Execute("INSERT INTO DestinationTable (TableField1, TableField2) SELECT ExistingInformation.Existing1, ExistingInformation.Existing2 FROM ExistingInformation;")
End Sub

Open in new window

0
Comment
Question by:developingprogrammer
  • 2
  • 2
5 Comments
 
LVL 40

Expert Comment

by:als315
ID: 39719626
Do you like to insert some default values if you have no existing data in ExistingInformation?
0
 

Author Comment

by:developingprogrammer
ID: 39719636
Yes I would = )
0
 
LVL 40

Assisted Solution

by:als315
als315 earned 1000 total points
ID: 39719653
You can use construction like:
SELECT nz(ExistingInformation.Existing1, "something1"), nz(ExistingInformation.Existing2, "something2")
in combination with left join to ExistingInformation from some full table/query
0
 
LVL 52

Accepted Solution

by:
Gustav Brock earned 1000 total points
ID: 39719661
> can i use a mixture of 2 or must i write 2 queries?

You could create a union query and then use this once to insert all values. But it would be slower than just running the two queries you have.

/gustav
0
 

Author Comment

by:developingprogrammer
ID: 39719887
yup guys i agree, it may take a bit too much effort - i should just keep it simple = ) thanks guys!! = ))
0

Featured Post

Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question