Update table with SQL

R

Roger Svensson

Hi,

I have a SQL query that works fine on an SQL server database but not on an
equivalent Access database. Can anyone please help me tune the query to
function in Access?
The query looks like this:

update TABLE1 set Column1 = (select count(*) from TABLE2 where("Column2"=2))

/Roger
 
A

Allen Browne

Access will interpret the quotes as a literal string, so the where clause of
the query is comparing a literal string to a number.

Perhaps you want something like this:

update TABLE1 set Column1 =
(select count(*)
from TABLE2
where (Table2.Column2 = Table1.Column2));
 
R

Roger Svensson

I tried to type:
update TABLE1 set Column1 = (select count(*) from TABLE2
where([TABLE2].[Column2]=2))
Still without any success though...
 
J

John Spencer

How about using the DCount function? Access won't allow you to use
aggregate queries in an update query (other than in a where clause).

UPDATE TABLE1
SET Table1.Column1 =DCount("*","Table2","Column2 = 2")
 
R

Roger Svensson

Thanks John! You made my day...

Where can I get a good overview of those "hidden" Access functions? There
seems to be a lot of them...

/Roger
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top