Beast mode to extract the date based on a pattern

308 Views Asked by At

I am trying to extract the date from a field based on a pattern - If the first four characters of the field description are *SLD then I need to extract the date from the field description as output date else I need to take the date from the field orddate as the the output date..please find the table below:

description orddate output Date
*SLD 5/18/22 Rimel 5/2/2022 5/18/2022
SOLD mila 5/3/2022 5/3/2022
*SLD 5/23/22 345671 kilo 5/15/2022 5/23/2022
*SLD 5/14/22 jing ming 5/1/2022 5/14/2022
123566 5/12/2022 5/12/2022
1

There are 1 best solutions below

0
darrp On

I would do something like:

Case
    When Left(description,4) = '*SLD' Then 
        Replace( /*as months can have 1 or 2 digits, the resulting string could have some spaces that we need to clean*/
            Left( /* Remove characters after the date */
                Right(description, Len(description) - 5) /* Remove '*SLD ' */
                ,8
            )
            ,' ',''
        )
    Else orddate
End