I completely agree with OG. Note, that converting string in format
YYMMDD
to proper date is not easy job, because a century (age) part is missing. For example:
"
880521
" may become into:
18880521
or
19880521
or
20880521
Starting from MS SQL Server 2012, you can use:
DATEFROMPARTS (Transact-SQL) - SQL Server | Microsoft Docs[
^]. Note: you have to pass year, month and day as integer values. So, you have to split string
YYMMDD
into parts and
convert[
^] them to proper integer values.
Spliting text is another difficulty, because it depends on SQL server version.
Up to 2012, you need to use
SUSTRING()[
^] function.
Starting from 2016, you can use
STRING_SPLIT (Transact-SQL) - SQL Server | Microsoft Docs[
^]
BTW: you can create
user-defined function[
^], which gets a
YYMMDD
text and returns a proper date time (based on your century/age logic).