ambaxter, from the looks of it, you're trying to determine which stock quotes exist in your external db versus what is in your tv values, probably for the purposes of trying to synchronize the two.
If so, you could take the results of the query where the modx_site_tmplvar_contentvalues ids are all null (you can also just test the key field because that would mean they don't exist at all).
Using this list you could do an insert like this:
INSERT INTO modx_site_tmplvar_contentvalues (tmplvarid, contentid, value)
SELECT (20, 0, co_id)
FROM ssm_companies
LEFT JOIN
modx_site_tmplvar_contentvalues
ON
ssm_companies.id=modx_site_tmplvar_contentvalues.value
WHERE
active!=0
order BY
ssm_companies.id
That would insert the new company ids from the stock quotes table, but you would have to then go back an manually update any value with a contentid = 0 to the actual page to which it points.
From the looks of the data, it looks like the tv values per company id are pointing to different pages, so Smith and Wesson is pointing to 1131. If this is a 1:1 mapping, you might want to look at combining the pages to have the content load more dynamically, which would save you creating more pages (one for each company?). If these were all for one page you could automate this.
My apologies if I've completely misunderstood what you're trying to get at.