Solved

insert sql using both VALUES and SUB-QUERY

Posted on 2013-12-14
5
355 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 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 51

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

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
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…

627 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