Ask a Question related to ASP Database, Design and Development.
-
McKirahan #1
SELECT and INSERT
Is there a way to do the SELECT and INSERT in a single SQL statement in
MS-Access?
McKirahan Guest
-
insert into...select using the same table
How can I do the following in MySQL. insert into table1 (col1, col2, col3) select col1, col2, somevalue as col3 from table1 MySQL doesn't... -
What's faster - loop for insert or insert...select.
What is faster if I'm moving large numbers of records (anywhere from 10,000 to 300,000 records per archive) from one query to another table? 1)... -
Insert from Select
I'm trying to insert from a select statement but it is giving me an error that I "Cannot modify table or view used in subquery." on my where clause.... -
How to select and then loop while insert
I need help in writing a stored procedure on SQL Server 2000. Basically the stored procedure's primary task is to generate invoice records and... -
cursor with insert/select
I have a cursor that inserts rows in a table. Simple enough stuff, but I'm a little confused by something that's happening. Instead of the sproc... -
Bob Barrows [MVP] #2
Re: SELECT and INSERT
McKirahan wrote:
Didn't I answer this yesterday?> Is there a way to do the SELECT and INSERT in a single SQL statement
> in MS-Access?
The answer is Yes.
Insert into tablename (<column list>)
Select <column list>
FROM tablename
Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Bob Barrows [MVP] Guest
-
McKirahan #3
Re: SELECT and INSERT
"Bob Barrows [MVP]" <reb01501@NOyahoo.SPAMcom> wrote in message
news:#mLQwS#dEHA.3612@TK2MSFTNGP09.phx.gbl...Actually, you didn't. You saw it yesterday in the post called "Database> McKirahan wrote:>> > Is there a way to do the SELECT and INSERT in a single SQL statement
> > in MS-Access?
> Didn't I answer this yesterday?
>
> The answer is Yes.
>
> Insert into tablename (<column list>)
> Select <column list>
> FROM tablename
>
> Bob Barrows
>
> --
> Microsoft MVP - ASP/ASP.NET
> Please reply to the newsgroup. This email account is my spam trap so I
> don't check it very often. If you must reply off-line, then remove the
> "NO SPAM"
>
Efficiency" but you only answered the first of three questions. Thank you
for both of your answers.
McKirahan Guest
-
Aaron [SQL Server MVP] #4
Re: SELECT and INSERT
> Actually, you didn't. You saw it yesterday in the post called "Database
??? You must not have bothered to read far enough down his post. I see> Efficiency" but you only answered the first of three questions.
this (scroll down, please!):
Yes, there are two ways:> Is there a way to do the SELECT and INSERT in a single SQL statement?
1. You can create a linked table in your Access database and do a simple:
strSQ2 = "INSERT INTO AR1_CustomerMaster"
strSQ2 = strSQ2 & " (CustomerNumber, CustomerNumber)"
strSQ2 = strSQ2 & " SELECT CustomerNumber, CustomerName"
strSQ2 = strSQ2 & " FROM AR1_CustomerMaster_lnk"
2. You can use an IN clause in your SELECT statement:
Dim strSQ2
strSQ2 = "INSERT INTO AR1_CustomerMaster"
strSQ2 = strSQ2 & " (CustomerNumber, CustomerNumber)"
strSQ2 = strSQ2 & " SELECT CustomerNumber, CustomerName"
strSQ2 = strSQ2 & " FROM AR1_CustomerMaster "
strSQ2 = strSQ2 & " IN '' [ODBC; DSN=ODBC_System_DSN;]"
When you execute a statement that does not return records, you need to tell>
>
> Also, what is the value of "adExecuteNoRecords"?
the Command object (yes, a Command object is being used by ADO here) to skip
the creation of a recordset object. If you do not use "adExecuteNoRecords",
it will create a recordset object even though your query does not return any
records.
Aaron [SQL Server MVP] Guest
-
McKirahan #5
Re: SELECT and INSERT
"Aaron [SQL Server MVP]" <ten.xoc@dnartreb.noraa> wrote in message
news:eX5dMUKeEHA.1764@TK2MSFTNGP10.phx.gbl...tell>> > Actually, you didn't. You saw it yesterday in the post called "Database
> > Efficiency" but you only answered the first of three questions.
> ??? You must not have bothered to read far enough down his post. I see
> this (scroll down, please!):
>
>
>
>
>
>
>
>>> > Is there a way to do the SELECT and INSERT in a single SQL statement?
> Yes, there are two ways:
>
> 1. You can create a linked table in your Access database and do a simple:
> strSQ2 = "INSERT INTO AR1_CustomerMaster"
> strSQ2 = strSQ2 & " (CustomerNumber, CustomerNumber)"
> strSQ2 = strSQ2 & " SELECT CustomerNumber, CustomerName"
> strSQ2 = strSQ2 & " FROM AR1_CustomerMaster_lnk"
>
>
>
> 2. You can use an IN clause in your SELECT statement:
>
> Dim strSQ2
> strSQ2 = "INSERT INTO AR1_CustomerMaster"
> strSQ2 = strSQ2 & " (CustomerNumber, CustomerNumber)"
> strSQ2 = strSQ2 & " SELECT CustomerNumber, CustomerName"
> strSQ2 = strSQ2 & " FROM AR1_CustomerMaster "
> strSQ2 = strSQ2 & " IN '' [ODBC; DSN=ODBC_System_DSN;]"
>
>>> >
> >
> > Also, what is the value of "adExecuteNoRecords"?
> When you execute a statement that does not return records, you need toskip> the Command object (yes, a Command object is being used by ADO here) to"adExecuteNoRecords",> the creation of a recordset object. If you do not useany> it will create a recordset object even though your query does not returnMy humble apology -- you're right.> records.
>
>
I guess I saw all that "strSQ2 = " stuff and thought it was my original
post.
Thanks again for your responses which are always of the highest quality.
McKirahan Guest



Reply With Quote

