473,385 Members | 1,863 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

How to make a local table based on results of a remote sql stored procedure

33
Hi, From a MS Access97 db i am attempting to write a function that will run a SQL 2000 stored procedure(SP). As part of the function, i need to add some selection criteria that will be used at the point the SP is executed.

I have defined the ODBC settings and tested these ok along with the selection citeria of Date / DepotID / ContractID

How do i call / execute the SP to make a local table of the results whilst also apply the selection criteria?

An example of one of my attempts is below;
Expand|Select|Wrap|Line Numbers
  1. DoCmd.Execute "SELECT SPNAME.* INTO " _
  2. & "[LocalTableName] WHERE DeliveryDate = 'datDeliveryDate' & DepotID = 'DepotID' & ContractID = 'ContractID'"
At this current time, the above code appears to run without error but no records are returned - as if it hasn't run at all.
Thanks inadvance
Nov 8 '11 #1

✓ answered by sierra7

Q,
If you go this route your parameters are hard coded into the SP

If you have access to the SQL Management Studio just create a View (if you are joining tables) or link directly to the table (in Access;- External Data,ODBC,Link option, select the DSN, then point to the table name or View)
If you then substitute this name for SPNAME in your first post, add a FROM clause and all should be ok.
S7

4 1728
sierra7
446 Expert 256MB
Hi,
I presume by testing the link you mean your SP is listed in the Queries tab of Access and when you double click on it, it opens and shows the data in Datasheet view?

If this does not happen then your code won't run. (Well, It might but you won't get any data!)

To link to an SP you need to create a Pass-Through query and set the 'Returns Records=Yes' in the property sheet.

Personally, for the simple task in hand I would have created a view or linked directly to the table.
S7
Nov 9 '11 #2
sierra7
446 Expert 256MB
Just noticed that you have missed out a FROM clause in your SQL statement
S7
Nov 9 '11 #3
Quizzed
33
Thanks S7, appreciate your comments.
Rather than complicate my first attempt with an insert, i have changed my query to be the following;

Expand|Select|Wrap|Line Numbers
  1. DECLARE @DeliveryDate smalldatetime
  2. DECLARE @DepotID int
  3. DECLARE @ContractID int
  4.  
  5. set @deliverydate = '2011.11.09'
  6. set @depotid = 43
  7. set @contractid = 21
  8.  
  9. EXEC AMT_DipsOrderSummaryByDate @DeliveryDate, @DepotID, @ContractID
The SP does exist within the Queries tab and the return records para is set to Yes. Unfortunately no records are being returned. The msg box is;

Pass-through query with ReturnRecords property set to True did not return any records.

Appreciate if you can suggest a next step. Tks.
Nov 9 '11 #4
sierra7
446 Expert 256MB
Q,
If you go this route your parameters are hard coded into the SP

If you have access to the SQL Management Studio just create a View (if you are joining tables) or link directly to the table (in Access;- External Data,ODBC,Link option, select the DSN, then point to the table name or View)
If you then substitute this name for SPNAME in your first post, add a FROM clause and all should be ok.
S7
Nov 9 '11 #5

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

Similar topics

0
by: Charley | last post by:
Hi, My local procedure needs to call a remote stored procedure which dblink name is built at the run time depending on the input parameter to the local procedure. Therefore depending on the...
2
by: Samir Pandey | last post by:
I have a table which contains approx 3,00,000 records. I need to import this data into another table by executing a stored procedure. This stored procedure accepts the values from the table as...
2
by: HumanJHawkins | last post by:
Hi, I am using data from multiple databases and/or queries. It would greatly simplify and speed things up if I could use CONTAINS in processing the results. However, "CONTAINS" requires the data...
3
by: Rudi | last post by:
Hello Forum ! I want to have the tablename "dbo.Enbxxxx" as an additional parameter for a procedure like this: ALTER Procedure prcSucheUNR ( @UNR int ) As
4
by: John | last post by:
Hi everyone, I have a stored procedure which I use to query a table. The first part of the stored procedure uses a cursor to update a temp table whilst the second part of the query actually...
0
by: Kolar | last post by:
1.. EXEC sp_addlinkedserver ServerName1, N'SQL Server' EXEC sp_addlinkedserver ServerName2 EXEC sp_configure 'remote access', 1 RECONFIGURE GO 2.. Stop and restart the first SQL Server. 3.....
6
by: Terentius Neo | last post by:
Is it possible to combine (in DB2 UDB 8.1) a stored procedure and a select statement? I mean something like this: Select c.number, call procedure( c.number ) as list from table c With best...
1
by: VivN | last post by:
I am using the following code to open a recordset returned by a SQL server stored procedure: sConn = "Provider='SQLOLEDB';Data Source='Aph-Ework-Dev';" & _ "Initial...
5
by: adi | last post by:
Hi all, Seems like a fundamental question to me but I dont have a definite answer for it, Gurus please enlighten me. I have a table 'Table1' whose structure changes dynamically based on some...
3
by: Kirsten Østerga | last post by:
I have a table that I insert data into using the following stored procedure: CREATE PROCEDURE . AS BEGIN SET NOCOUNT ON; DECLARE @Periode DateTime, @NyPeriode DateTime SET @NyPeriode...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.