1

I'm using MS Access 2019 and ahve two tables:

  • table_a (id_a, number_a)
  • table_b (id_b, name_b)

This UPDATE statement doesn't work:

UPDATE table_a
SET number_a = (SELECT COUNT(*) FROM table_b WHERE id_b IN (1,3) AND name_b=@name) 
WHERE id_a=1;

Error

Operation must use an updateable query

2

2 Answers 2

1
UPDATE table_a 
SET table_a.number_a = DCount("*","table_b","id_b IN (1,3) AND name_b=@name")
WHERE table_a.id_a=1;

or

UPDATE table_a 
SET table_a.number_a = DCount("*","table_b","id_b IN (1,3) AND name_b=" & @name)
WHERE table_a.id_a=1;

depends on what is @name, where it is defined and how it is substituted with its value.

Sign up to request clarification or add additional context in comments.

Comments

0

Why don't you capture value then assign it like below

DECLARE @COUNT_B INT
SELECT @COUNT_B = COUNT(*) FROM table_b WHERE id_b IN (1,3) GROUP BY id_b

UPDATE table_a
SET number_a = @COUNT_B
WHERE id_a=1;

1 Comment

This is not valid syntax for MS Access.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.