Wrox Home  
Search P2P Archive for: Go

  Return to Index  

access thread: Select Into from Store Procedure


Message #1 by "Glen Yagami" <glenyagami@y...> on Wed, 18 Dec 2002 05:15:11
I want to insert the resulting rows of a store procedure to a new table 
but when I execute, the code returns "Invalid object name 'sprTour'".

With cmd1
   .ActiveConnection = CurrentProject.Connection
   .CommandType = adCmdText
   .CommandText = "select tourcode into someTable from sprTour"
   .Execute
End With

I've changed the CommandType but it just shows another error message.

Thanks.
Glen
Message #2 by "Haslett, Andrew" <andrew.haslett@i...> on Wed, 18 Dec 2002 15:35:35 +1030
If you want to INSERT then you shouldn't be using SELECT.

http://www.w3schools.com/sql/sql_insert.asp

Cheers,
Andrew

-----Original Message-----
From: Glen Yagami [mailto:glenyagami@y...]
Sent: Wednesday, 18 December 2002 3:45 PM
To: Access
Subject: [access] Select Into from Store Procedure


I want to insert the resulting rows of a store procedure to a new table 
but when I execute, the code returns "Invalid object name 'sprTour'".

With cmd1
   .ActiveConnection = CurrentProject.Connection
   .CommandType = adCmdText
   .CommandText = "select tourcode into someTable from sprTour"
   .Execute
End With

I've changed the CommandType but it just shows another error message.

Thanks.
Glen

IMPORTANT - PLEASE READ ******************** 
This email and any files transmitted with it are confidential and may 
contain information protected by law from disclosure. 
If you have received this message in error, please notify the sender 
immediately and delete this email from your system. 
No warranty is given that this email or files, if attached to this 
email, are free from computer viruses or other defects. They 
are provided on the basis the user assumes all responsibility for 
loss, damage or consequence resulting directly or indirectly from 
their use, whether caused by the negligence of the sender or not.
Message #3 by "Carnley, Dave" <dcarnley@a...> on Wed, 18 Dec 2002 09:46:44 -0600
it looks like you are trying to select from a stored procedure?  that's not
valid syntax, even if your procedure returns a row set.  There are a couple
of choices for you, though:  you can modify your stored procedure to create
the table, or you can use VBA to create the table.  

Assuming this is on a SQL Server backend, for modifying the procedure:
Somewhere in that proc, if it returns a record set, is a SELECT.  Modify
that select stmt into a create table stmt. This has some limitations though,
like providing a dynamic table name can be done but it isn't easy.

using VBA, but only if a relatively small data set, you can return the
results of the original unmodified stored procedure into an ADO recordset,
and then loop through that to push rows into a table.  But if this is more
than a few 100,000 rows this is probably not a good idea.

hope this helps,
David



-----Original Message-----
From: Glen Yagami [mailto:glenyagami@y...]
Sent: Tuesday, December 17, 2002 11:15 PM
To: Access
Subject: [access] Select Into from Store Procedure


I want to insert the resulting rows of a store procedure to a new table 
but when I execute, the code returns "Invalid object name 'sprTour'".

With cmd1
   .ActiveConnection = CurrentProject.Connection
   .CommandType = adCmdText
   .CommandText = "select tourcode into someTable from sprTour"
   .Execute
End With

I've changed the CommandType but it just shows another error message.

Thanks.
Glen
Message #4 by "Gerald, Rand" <RGerald@u...> on Wed, 18 Dec 2002 11:31:31 -0600
MS SQL Server and Access allow the "Select {list of fieldnames} Into
tableName" syntax.  However, it is not portable to other SQL platforms.

The way you have used the SQL text, sprTour must be the name of a 
table. I'm
not certain that the output of a stored procedure is acceptable in this
context.  If the stored procedure were to create a temporary table, 
then you
could do a SELECT ... INTO ... FROM ... based upon the temporary table.

Rand E Gerald
Database Specialist
Information Services / Operations
Bah=E1'=ED National Office
1233 Central St.
Evanston IL 60201
(xxx) xxx-xxxx

-----Original Message-----
From: Glen Yagami [mailto:glenyagami@y...]
Sent: Tuesday, December 17, 2002 23:15
To: Access
Subject: [access] Select Into from Store Procedure

I want to insert the resulting rows of a store procedure to a new table
but when I execute, the code returns "Invalid object name 'sprTour'".

With cmd1
   .ActiveConnection =3D CurrentProject.Connection
   .CommandType =3D adCmdText
   .CommandText =3D "select tourcode into someTable from sprTour"
   .Execute
End With

I've changed the CommandType but it just shows another error message.

Thanks.
Glen

  Return to Index