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
Nesta página do site você pode assistir ao vídeo on-line SQL Issue: Data Type Conversion(String to DateTime) while Data Loading duração hora minuto segundo em boa qualidade , que foi baixado pelo usuário TheSantanuGhosh 01 Janeiro 1970, compartilhe o link com seus amigos e conhecidos, no youtube este vídeo já foi visto 355 vezes e gostou 4 espectadores. Boa visualização!