Solved

insert sql using both VALUES and SUB-QUERY

Posted on 2013-12-14
5
343 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
Comment Utility
Do you like to insert some default values if you have no existing data in ExistingInformation?
0
 

Author Comment

by:developingprogrammer
Comment Utility
Yes I would = )
0
 
LVL 39

Assisted Solution

by:als315
als315 earned 250 total points
Comment Utility
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
Comment Utility
> 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
Comment Utility
yup guys i agree, it may take a bit too much effort - i should just keep it simple = ) thanks guys!! = ))
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

771 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now