Solved

insert sql using both VALUES and SUB-QUERY

Posted on 2013-12-14
5
348 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 39

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 39

Assisted Solution

by:als315
als315 earned 250 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 49

Accepted Solution

by:
Gustav Brock earned 250 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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

777 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