UPDATE **name_table**
SET is_valid_cf=1
WHERE LENGTH(codfisc)=16
AND codfisc REGEXP '^[A-Za-z]{6}[0-9]{2}[A-Za-z]{1}[0-9]{2}[A-Za-z]{1}[0-9]{3}[A-Za-z]{1}$'
;
UPDATE **name_table**
SET sesso=IF(CAST(SUBSTR(codfisc,10,2) AS DECIMAL(10,0))>40, 'F', 'M')
WHERE is_valid_cf=1
;
UPDATE **name_table**
SET datanascita=IF(
      CAST(SUBSTR(YEAR(now()),3,2) AS DECIMAL(10,0)) >= CAST(SUBSTR(codfisc,7,2) AS DECIMAL(10,0))
    , CONCAT('20',SUBSTR(codfisc,7,2))
    , CONCAT('19',SUBSTR(codfisc,7,2))
)
WHERE is_valid_cf=1
;
UPDATE **name_table**
SET datanascita=CONCAT(datanascita
    , CASE SUBSTR(codfisc,9,1)
            WHEN 'A' THEN '01'
            WHEN 'B' THEN '02'
            WHEN 'C' THEN '03'
            WHEN 'D' THEN '04'
            WHEN 'E' THEN '05'
            WHEN 'H' THEN '06'
            WHEN 'L' THEN '07'
            WHEN 'M' THEN '08'
            WHEN 'P' THEN '09'
            WHEN 'R' THEN '10'
            WHEN 'S' THEN '11'
            WHEN 'T' THEN '12'
            else '01'
    END
)
WHERE is_valid_cf=1
;
UPDATE **name_table**
SET datanascita=CONCAT(datanascita
    , SUBSTR(CONCAT('00',CAST(CAST(SUBSTR(codfisc,10,2)  AS DECIMAL(10,0)) MOD 40 AS CHAR)),-2,2)
)
WHERE is_valid_cf=1
;
UPDATE **name_table**
SET cittanascita=SUBSTR(codfisc,12,4)
WHERE is_valid_cf=1
