; with
cte as
(
select t1.ID, t1.Content
from table1 t1
union all
select ID = case when t1.ID is null then t2.ID
else NULL
end,
t2.Content
from table2 t2
left join table1 t1 on t2.ID = t1.ID
)
select ID = case when ID is null
then max(ID) over()
+ row_number() over (partition by ID order by Content)
else ID
end,
Content
from cte
order by ID
KH
Time is always against us