-- -------------------------------------------
-- sod_func AB -> sod_func N conversion script
-- -------------------------------------------

CREATE TABLE IF NOT EXISTS `sod_sod_func_func` (
  risk_id INT NOT NULL,
  sod_func_id INT NOT NULL,
  position INT NOT NULL,
  PRIMARY KEY (risk_id, sod_func_id));
	INSERT INTO sod_sod_func_func (risk_id, sod_func_id, position) 
	SELECT rule_id , func_a , 0 FROM sod_sod_func WHERE func_a IS NOT NULL;
	INSERT INTO sod_sod_func_func (risk_id, sod_func_id, position) 
	SELECT rule_id , func_b , 1  FROM sod_sod_func WHERE func_b IS NOT NULL
	ON DUPLICATE KEY UPDATE position = 0;