 SELECT `q`.`id`,        `t`.`question_order`,       `q`.`text_brief`,
        `q`.`text_full`, 'text',                     'optional',
         NULL,           `t`.`funder_template_id`,   `q`.`created_at`,
-       `q`.`updated_at`, NULL,                       NULL
+       `q`.`updated_at`, NULL,                       0
 FROM `dmp`.`questions`          AS `q`
 JOIN `dmp`.`question_templates` AS `t` ON `t`.`question_id` = `q`.`id`;
 

JOIN `dmp`.`question_templates` AS `t` ON `t`.`question_id` = `h`.`question_id`
JOIN `dmp`.`funder_templates`   AS `f` ON `f`.`id`          = `t`.`funder_template_id`
WHERE `h`.`institution_id` IS NULL
      AND LENGTH(`h`.`help_text`) > 50
GROUP BY `f`.`funder_id` ASC, `h`.`help_text` ASC;

INSERT INTO `dmp2`.`resources` (

JOIN `dmp`.`question_templates` AS `t` ON `t`.`question_id` = `h`.`question_id`
JOIN `dmp`.`funder_templates`   AS `f` ON `f`.`id`          = `t`.`funder_template_id`
WHERE `h`.`institution_id` IS NULL
AND LENGTH(dmp2.fnStripTags(`h`.`help_text`)) <= 50
GROUP BY `f`.`funder_id` ASC, `h`.`help_text` ASC;

# finally copy DMP1 help texts into DMP2 resources where institution ID is not NULL,
# but only for unique combinations of institution ID and help text
INSERT INTO `dmp2`.`resources` (
       `resource_type`,    `value`,                   `label`,
       `created_at`,       `updated_at`,              `text`,
       `old_help_text_id`, `old_suggested_answer_id`, `old_institution_id`,
       `old_funder_id`)
SELECT 'help_text',         NULL, CONCAT(LEFT(dmp2.fnStripTags(`help_text`) ,50), '...'),
       `created_at`,       `updated_at`,              `help_text`,
       `id`,                NULL,                     `institution_id`,
        NULL
FROM `dmp`.`help_texts`
WHERE `institution_id` IS NOT NULL
AND LENGTH(dmp2.fnStripTags(`h`.`help_text`)) > 50
GROUP BY `institution_id` ASC, `help_text` ASC;

INSERT INTO `dmp2`.`resources` (
       `resource_type`,      `value`,                   `label`,
       `created_at`,         `updated_at`,              `text`,
       `old_help_text_id`,   `old_suggested_answer_id`, `old_institution_id`,
       `old_funder_id`)
SELECT 'help_text',           NULL,      LEFT(dmp2.fnStripTags(`help_text`), 50),
       `created_at`,         `updated_at`,              `help_text`,
       `id`,                  NULL,                     `institution_id`,
        NULL
FROM `dmp`.`help_texts`
WHERE `institution_id` IS NOT NULL
AND LENGTH(dmp2.fnStripTags(`h`.`help_text`)) <= 50
GROUP BY `institution_id` ASC, `help_text` ASC;

# now do the same thing for suggested answers 
