The new template variable may already exist, but do you already have entries in the [prefix]site_tmplvar_contentvalues table for it? That insert isn’t inserting new template variables, just new values for an existing template variable (with the given id).
Just to clarify: I’m assuming that you’ve already created this template variable, but every resource that has the other two TVs doesn’t have a value for the new one, and needs to have those two values combined.
If there are any resources that are already using this TV and the other two, you will end up with some duplicate values in your table for the same resource/tv combination -
that would be a very bad thing. I would make sure to flush these values before you do the insert:
select t3.*
from
[prefix]site_tmplvar_contentvalues t1
, [prefix]site_tmplvar_contentvalues t2
, [prefix]site_tmplvar_contentvalues t3
where
t1.contentid = t2.contentid
and t3.contentid = t2.contentid
and t3.tmplvarid = [new_tv_id]
and t1.tmplvarid = [first_old_tv_id]
and t2.tmplvarid = [second_old_tv_id]
That should give you a good idea about existing TV values you might want to delete.
Please make a backup of your database before you try any of these. My examples are certainly not typo-proof.
EDIT:
Again the problem is to copy the value of 2 custom TVs to a modx default variable (summary).
I just noticed this bit which really changes the problem quite a bit - sorry! I should have read that a little bit more closely. Here’s a very messy, very slow modification that *should* do the trick, but I’m really just doing this off the top of my head, so again be sure to make a backup:
update [prefix]site_content set introtext = (
select concat(t1.value, 'separator', t2.value)
from
[prefix]site_tmplvar_contentvalues t1
, [prefix]site_tmplvar_contentvalues t2
where
t1.contentid = t2.contentid
and t1.contentid = [prefix]site_content.id
and t1.tmplvarid = [first_old_tv_id]
and t2.tmplvarid = [second_old_tv_id]
) where id in (
select [prefix]site_content.id
from [prefix]site_tmplvar_templates
where
[prefix]site_content.template = [prefix]site_tmplvar_templates.templateid
and [prefix]site_tmplvar_templates.tmplvarid in ([first_old_tv_id], [second_old_tv_id])
);