I have the following (minimal) example
-- prepare some data
DECLARE @src TABLE (txt varchar(MAX), id bigint)
insert into @src (txt, id) values ('foo', 1)
insert into @src (txt, id) values ('bar', 1)
insert into @src (txt, id) values ('baz', 1)
insert into @src (txt, id) values ('foo', 2)
insert into @src (txt, id) values ('bar', 2)
-- prepare json
declare @dst TABLE (json varchar(max), id bigint)
insert into @dst (json, id) values ('[]', 1)
insert into @dst (json, id) values ('[]', 2)
-- peek the expected result
select s.txt, d.id from @src s
inner join @dst d
on d.id = s.id
-- now update
update @dst set json = JSON_MODIFY(d.json, 'append strict $', s.txt)
from @src s
inner join @dst d
on d.id = s.id
-- let's see
select * from @dst
I would expect the result to be ['foo', 'bar', 'baz'] for id 1 in the @dst table.
I have one very similar case in which this works but I can't get it working again.
What am I missing here?