SQL Issue: Data Type Conversion(String to DateTime) while Data Loading

Publicado el: 01 enero 1970
en el canal de: TheSantanuGhosh
355
4

Error: while inserting data from staging table to target table
Conversion failed when converting date and/or time from character string.
Track: Find the records in which the issue exits
Resolution: Solution to fix the data type issue

query to find which records has the issue:
select *
from
(Select top 100 Serial_Number, Name, Admission_Date,
CASE WHEN TRY_CONVERT(datetime, Admission_Date) IS NULL
THEN 'Cast failed'
ELSE 'Cast succeeded'
END AS Result
from student_staging) a
where Result = 'Cast failed';

Solution: how to fix the data type issue
insert into student
select serial_number, name,
CASE WHEN Admission_Date = ''
THEN NULL
ELSE
(CASE WHEN TRY_CONVERT(datetime, Admission_Date) IS NULL
THEN NULL
ELSE cast ( Admission_Date as datetime)
END )
END AS Admission_Date
from student_staging


En esta página del sitio puede ver el video en línea SQL Issue: Data Type Conversion(String to DateTime) while Data Loading de Duración hora minuto segunda en buena calidad , que subió el usuario TheSantanuGhosh 01 enero 1970, comparta el enlace con amigos y conocidos, en youtube este video ya ha sido visto 355 veces y le gustó 4 a los espectadores. Disfruta viendo!