Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Create Table on SQL Server from Access

Author  Topic 

ggrinton
Starting Member

5 Posts

Posted - 2005-03-16 : 21:55:07

I am using ODBC from Access to access an SQL Server database (both running on Win200x platforms. What I need to do is to create, on the local machine, a small table (anything from a few rows to a few hundred rows) with some selection parameters. This is based on user input through a form-based wizard interface. The next step is to execute a join between that table and the humongous SQL Server table to extract a results set. I know it is bad news to try to join a local table with a 'remote' one, and that is confirmed by experience.

What I need is some help to know how to "move" the local table to the server so that I can do the whole join on the Server using a pass-through query. Is it possible to create a temporary table on the Server which I can then use in the primary query which does the join?

I have the functionality all working, using a join between the Access table and the linked SQL Server table, but am hoping that by eliminating the inter-machine link the performance will be improved.

My experience is in MS Access, but I don't have much experience in SQL Server or the use of pass-through queries. I won't be offended if I am told the question does not make much sense, but I am not sure how else to proceed.

Any pointers to sources of advice (eg URLs, books, gurus(?) etc) would be appreciated.


Thanks.
Geoffrey

rrb
SQLTeam Poet Laureate

1479 Posts

Posted - 2005-03-21 : 20:29:12
Hi Geoff

What version of Access - are you using an Access .adp project or are you working from an Access .mdb file?

(ie are you using DAO 3.6? - that's the same question in case you're not sure)

--
I hope that when I die someone will say of me "That guy sure owed me a lot of money"
Go to Top of Page

ggrinton
Starting Member

5 Posts

Posted - 2005-03-21 : 21:07:28
quote:
Originally posted by rrb
What version of Access - are you using an Access .adp project or are you working from an Access .mdb file?



I am working with Access 2002, from a .mdb file, and using DAO3.6.
Thanks for the response.
Geoffrey
Go to Top of Page

rrb
SQLTeam Poet Laureate

1479 Posts

Posted - 2005-03-21 : 21:11:12
Geoff

are you envisaging creating the table and then deleting it for each query, or can you leave the table on the server and just change data?

--
I hope that when I die someone will say of me "That guy sure owed me a lot of money"
Go to Top of Page

ggrinton
Starting Member

5 Posts

Posted - 2005-03-21 : 21:25:08
quote:
Originally posted by rrb
are you envisaging creating the table and then deleting it for each query, or can you leave the table on the server and just change data?


I had envisaged creating and deleting it each time. Just a matter of cleaning up after myself, really, but it has the advantage that the application can be self-contained. If it is a permanent table, then I would need a separate step to create the table somehow, and a user may not know if that has been done already. (Not mentioned in my original posting, but there are in fact several databases I need to work with - dev, test, short-term repository, long-term repository, etc.)

Geoffrey
Go to Top of Page

rrb
SQLTeam Poet Laureate

1479 Posts

Posted - 2005-03-21 : 21:27:58
OK, I think I can help you. There's a few ways you can do this, but I'll go with simple and we can get more complicated from there....

Do you know how to create a pass-through query?

--
I hope that when I die someone will say of me "That guy sure owed me a lot of money"
Go to Top of Page

ggrinton
Starting Member

5 Posts

Posted - 2005-03-21 : 21:32:26
I know how to create one but my problem is that I am not sure what to put in it

Geoffrey
Go to Top of Page

rrb
SQLTeam Poet Laureate

1479 Posts

Posted - 2005-03-21 : 21:37:57
Well, I would envisage 4 steps
* Create a table (using Passthrough)
* Use ADO to fill it with your search parameters
* Run the query (using passthrough)
* Delete the table (using passthrough)
Does that sound OK?


Step one - create the table:
Here's an example - but if you want to give the the details of the table I can do the proper string for you.

Create the Passtrhough query and point it to the database (tell me if you're not sure how to do that)
The SQL will be something like:
create table RobsTest (id int identity(1,1), col1 varchar(50))


Post back the actual SQL you use so I can duplicate it here....


--
I hope that when I die someone will say of me "That guy sure owed me a lot of money"
Go to Top of Page

ggrinton
Starting Member

5 Posts

Posted - 2005-03-21 : 22:15:42
Thanks Rob. I'm with you so far. The table I create, tblSelect, has 4 text fields (say 50 chars wide) called Parm1-4. (In my prototype, this table is generated by another batch of queries, of course, based on user inputs.) Then I run a query like:

SELECT dboSVR_Name, dbo_SVR.DateTime, dbo_SVR.SampledValue
FROM dbo_SVR INNER JOIN tblSelect ON (dbo_SVR.Parm1 = tblSelect.Parm1) AND (dbo_SVR.Parm2 = tblSelect.Parm2) AND (dbo_SVR.Parm3 = tblSelect.Parm3) AND (dbo_SVR.Parm4 = tblSelect.Parm4)
WHERE (((dbo_SVR.DateTime)>=#1/31/2005 13:50:0# And (dbo_SVR.DateTime)<#2/22/2005 13:50:0#));


where the date window parameters are also specified by the user. Generating the SELECT is the bit I can probably work out, but I have not done the other steps like create, populate and delete. I am very grateful for you patience and assistance.

Geoffrey
Go to Top of Page

rrb
SQLTeam Poet Laureate

1479 Posts

Posted - 2005-03-21 : 22:21:13
Sorry Geoff

I've got to go to a meeting for about an hour - here's an example procedure
Public Function DoQuery() As Boolean
Dim db As Database
Dim qdf As QueryDef
Dim rst As Recordset
Dim SQL As String

On Error GoTo Err_DoQuery

Set db = CurrentDb

'Create parameter table
Set qdf = db.CreateQueryDef("")
qdf.Connect = "ODBC;DSN=local;Trusted_Connection=yes;"
qdf.SQL = "create table tempQueryParam (id int identity(1,1), param1 varchar(50))"
qdf.ReturnsRecords = False
qdf.Execute

'Insert Search Parameters
qdf.SQL = "insert into tempQueryParam (param1) values ('Paris')"
qdf.Execute

'Run Search
qdf.ReturnsRecords = True
qdf.SQL = "select spy from spies a inner join tempQueryParam b on a.town = b.param1"
Set rst = qdf.OpenRecordset()

Do While Not rst.EOF
Debug.Print rst.Fields("spy")
rst.MoveNext
Loop
rst.Close

'Clean up
qdf.ReturnsRecords = False
qdf.SQL = "drop table tempQueryParam"
qdf.Execute

Set qdf = Nothing
DoQuery = True

Exit_DoQuery:
Exit Function

Err_DoQuery:
MsgBox Err.Description
Resume Exit_DoQuery
End Function


I'll continue when I get back...

Cheers

--
I hope that when I die someone will say of me "That guy sure owed me a lot of money"
Go to Top of Page

rrb
SQLTeam Poet Laureate

1479 Posts

Posted - 2005-03-21 : 22:26:48
Ah, just got your email - this means your scripts will be something like
create table tblSelect (id int identity(1,1), param1 varchar(50), param2 varchar(50), param3 varchar(50), param4 varchar(50))"

then you can modify my example to build the insert string to insert values from a local table or query or whatever
then your select query will be exactly what you have BUT- you need to pass in the dates differently, do this instead
SELECT dboSVR_Name, dbo_SVR.DateTime, dbo_SVR.SampledValue
FROM dbo_SVR INNER JOIN tblSelect ON (dbo_SVR.Parm1 = tblSelect.Parm1) AND (dbo_SVR.Parm2 = tblSelect.Parm2) AND (dbo_SVR.Parm3 = tblSelect.Parm3) AND (dbo_SVR.Parm4 = tblSelect.Parm4)
WHERE (((dbo_SVR.DateTime)>=convert(Datetime, '1/31/2005 13:50:0', 101) And (dbo_SVR.DateTime)<convert(Datetime, '2/22/2005 13:50:0', 101));


Sorry - gotta rush - be back in an hour

good luck


--
I hope that when I die someone will say of me "That guy sure owed me a lot of money"
Go to Top of Page
   

- Advertisement -