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
 Other Forums
 MS Access
 Query from Pass-Through to Local

Author  Topic 

AjarnMark
SQL Slashing Gunting Master

3246 Posts

Posted - 2003-12-22 : 14:20:21
Looking for efficiency here, not just "something that works".

I need to pull a recordset from a SQL Server 2000 table into a local Access 2000 table, and will later massage, manipulate, and report on it. I have the syntax of my SQL query worked out, and it looks like this:

SELECT
isnull(u.lastname, '') + ', ' + isnull(u.firstname,'') as AgentName,
convert(varchar(10),a.abegintime, 101) as ActivityDate,
a.substateid as CategoryID,
sum(DATEDIFF(n, A.abegintime, A.aendtime)) as Duration,
min(wg.workgroupname) as Supervisor
FROM
activity a
LEFT JOIN users u ON a.entity = u.userid
LEFT JOIN workgroup_users wgu on u.userid = wgu.userid
LEFT JOIN workgroup wg on wgu.workgroupid = wg.workgroupid
WHERE
a.entitytype = 1
and a.abegintime BETWEEN '12/6/2003 00:00:00' AND '12/20/2003 00:00:00'
and a.substateid IN (5, 36, 12, 34, 8, 30, 35, 6, 7)
and wg.workgroupname like 'Team %'
and wg.status = 1
GROUP BY
isnull(u.lastname, '') + ', ' + isnull(u.firstname,''),
convert(varchar(10),a.abegintime, 101),
a.substateid
ORDER BY
1, 2, 3

One challenge is that the dates in red above will need to be assigned based on input criteria from a user. My understanding is that a Pass-Through query is the efficient approach to retrieve data from a SQL Server, but I don't have much experience playing in this part of Access. Based on Knookie's post at [url]http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=13137[/url] it appears that perhaps I can use a pass-through and just re-define the actual SQL statement in code. Do I understand that correctly?

And perhaps more important will be how do I efficiently get that result set inserted into my Access 2000 table. Do I need a second query that will do the INSERT ... SELECT with the first query as the source for the select? If so, will that retain the benefits of the pass-through aspect in the first query? Does anyone have any better suggestion?

Thanks!

--------------------------------------------------------
Visit the SQLTeam Weblogs at [url]http://weblogs.sqlteam.com[/url]

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2003-12-22 : 14:54:22
Honestly, I would just use a linked table to a view w/o the date criteria at all. Then just create a standard Access query using that linked table, and handle it w/ Access parameters (either a prompt or have it look at a form). Access will take the parameter and form a SQL statement incorporating it into the WHERE clause and then execute the query.

It is quite efficient --- usually. The JET Engine does a good job in general of passing in criteria to linked tables when doing joins between servers.

- Jeff
Go to Top of Page
   

- Advertisement -