472,341 Members | 1,795 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,341 software developers and data experts.

SQL STATEMENT to insert fields in a table from a query

Hello all,
can somebody help me out please, I try to create an sql statement to insert into a table everything that there is in a specific query. Including the Field names.

Thanks very very much!
Sep 26 '07 #1
2 1261
Hello all,
can somebody help me out please, I try to create an sql statement to insert into a table everything that there is in a specific query. Including the Field names.

Thanks very very much!

Do you mean how do you create an sql in VBA to append to a table? If so here's one example;

Dim MySQL As String
Dim MyDiagID As Long
Dim MyServiceID As Long
Dim MyCaseID As Long
Dim MyOriginEventID As Long
Dim MyStatusID As Long
Dim MyProviderID As Long

MyServiceID = Me.sfrmTriageHidden!cboDecision.Column(0)
MyProviderID = Me.sfrmTriageHidden!cboProvider.Column(0)
MyStatusID = 1 'Pending
MyDiagID = Me.sfrmTriageHidden!cboDiagID.Column(0)
MyOriginEventID = Me.sfrmTriageHidden!EventID
MyCaseID = Me.sfrmTriageHidden!CaseID

DoCmd.SetWarnings False
MySQL = "INSERT INTO tblEvents (DatePosted, ServiceID, ProviderID, StatusID, DiagID," & _
"OriginEventID, CaseID) " & _
"SELECT Date() as DatePosted, """ & MyServiceID & """ as ServiceID" & _
", """ & MyProviderID & """ as ProviderID, """ & MyStatusID & """ as StatusID " & _
", """ & MyDiagID & """ as DiagID, """ & MyOriginEventID & """ as OriginEventID" & _
", """ & MyCaseID & """ as CaseID;"
DoCmd.SetWarnings True

I prefer to declare pretty much all my variables and put them into the statement like so, mainly because it makes my code easier for me to read and understand/debug, but you could also put the fieldnames in directly.

If you meant you also wanted to insert the fieldnames themselves into your table I'd hazard a guess that what you really want is to make a table using the field names from your query? In which case you can replace my DoCmd.RunSQL MySQL line with code using the createtabledef method, well-documented in the Help files
Sep 26 '07 #2
Thnks for the answer!
with your help I came up with the following sql statement which works :
INSERT INTO [TBL] select * from [QUERY] ;

thanks a lot again
Sep 26 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

by: soni29 | last post by:
hi, i have a small question regarding sql, there are two tables that i need to work with on this, one has fields like: Table1: (id, name, street,...
by: serge | last post by:
/* This is a long post. You can paste the whole message in the SQL Query Analyzer. I have a scenario where there are records with values pointing...
by: ms | last post by:
I am running an insert statement from a dbf file and there is one record causing the insert to fail. A msg. is returned stating it is due to an...
by: Andy_Khosravi | last post by:
I have been trying to build a user friendly search engine for a small database I have created. I'm having some particular problems with one of my...
by: Geoffrey KRETZ | last post by:
Hello, I'm wondering if the following behaviour is the correct one for PostGreSQL (7.4 on UNIX). I've a table temp_tab with 5 fields...
by: Bob Alston | last post by:
I have a routine to copy data to new versions of my app via insert into sql statements. Unfortunately, due to evolution of my app, sometimes the...
by: Bob | last post by:
Hi all, I'm trying to import data, modify the data then insert it into a new table. The code below works fine for it but it takes a really long...
by: weird0 | last post by:
I have two tables accounts and ATM and i am trying to insert a tuple in ATM with accountId as foreign key. But even this simple work,I encounter...
by: franc sutherland | last post by:
Hello, I am using Access 2003. Is it possible to use string variables in the INSERT INTO statement? I am using the INSERT INTO statement to...
by: bonneylake | last post by:
Hey Everyone, Well recently i been inserting multiple fields for a section in my form called "serial". Well now i am trying to insert multiple...
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.