Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

insert sql using both VALUES and SUB-QUERY

Posted on 2013-12-14
5
Medium Priority
?
359 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 51

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
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…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

660 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