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

Опубликовано: 01 Январь 1970
на канале: 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


На этой странице сайта вы можете посмотреть видео онлайн SQL Issue: Data Type Conversion(String to DateTime) while Data Loading длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь TheSantanuGhosh 01 Январь 1970, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 355 раз и оно понравилось 4 зрителям. Приятного просмотра!