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

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

2 Answers2

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.

Akina
  • 39,301
  • 5
  • 14
  • 25
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;
Nguyễn Văn Phong
  • 13,506
  • 17
  • 39
  • 56