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
 T-SQL & Access SQL Syntax difference

Author  Topic 

mcrors_calhoun
Starting Member

22 Posts

Posted - 2007-05-18 : 12:07:49
Hi,

I am trying to update a table in an Access DB from data in another table. I do this in T-SQL like this

UPDATE LT
SET LT.Won = ud.Won
FROM League_Table LT
INNER JOIN
(SELECT teams.player_name AS Player,
Count(*) AS Won
FROM teams
LEFT JOIN
match_results
ON teams.player_name=match_results.result
WHERE match_results.result<>"Draw"
GROUP BY teams.player_name)ud
ON
LT.Player = ud.Player

But I am getting a syntax error when I try a similar sort of update in Access. I am not very familiar with Access, could someone let me know if it is possible to do an update like this in Access.

Thanks

McRors

nheidorn
Starting Member

28 Posts

Posted - 2007-05-18 : 12:46:40
Access doesn't directly support embedded subqueries. You have a few options depending on how your queries are implemented.

1) Save the UD portion of your SQL as a named query in Access and join the query to League_Table for the update
2) Use a SELECT INTO query to output the results of your UD query into a temp table, update League_Table from the temp table, and then drop the temp table

Option one can be completed in a single step, but requires named queries which is a practice I try to avoid whenever possible. Option two requires three steps, but it is often faster and it is the method I use most often.

You will also have to change the syntax of your update:

UPDATE LT
SET LT.Won = ud.Won
FROM League_Table LT INNER JOIN ...

becomes

UPDATE League_Table LT INNER JOIN ...
SET LT.Won = ud.Won

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-05-19 : 01:14:49
Also refer
http://weblogs.sqlteam.com/jeffs/archive/2007/03/30/Quick-Access-JET-SQL-to-T-SQL-Cheatsheet.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -