I have a table where the date of birth is 0000-00-00 where the format is YYYY-MM-DD. I have given the task to update these date to real DOB.
The DOB can only be extracted from the Identification Number which looks like 950313094353
(Not a real IC number) and IC is created like YYMMDDSNRAND
where SN
is state number e.g 09 and RAND
is just 4 random numbers e.g 4353.
From the IC number, I can get the date of birth by substring the first 6 digits.
The table
student_st
IC_NO D_BIRTH COUNTRY
------------ ---------- --------
940525053455 0000-00-00 MALAYSIA
The datatype of IC_NO is varchar, D_BIRTH is date and COUNTRY is varchar
My code that I tried is
UPDATE `student_st`
SET `D_BIRTH` = CONCAT('19', (SELECT SUBSTR(`IC_NO`, 1, 2) FROM `student_st` WHERE `COUNTRY`='MALAYSIA'),
'-', (SELECT SUBSTR(`IC_NO`, 3, 2) FROM `student_st` WHERE `COUNTRY`='MALAYSIA'),
'-', (SELECT SUBSTR(`IC_NO`, 5, 2) FROM `student_st` WHERE `COUNTRY`='MALAYSIA'))
WHERE `COUNTRY`='MALAYSIA' AND DATE(`D_BIRTH`)='0000-00-00'
This is the error that I'm getting
Error in query (1292): Truncated incorrect date value: '0000-00-00'
I don't know why the error is stating this.
From my code, the result that I expected is 19YY-MM-DD
where YY, MM and DD obtained from substring the IC number.