• DSC123 (7/27/2016)


    Morning all,

    Please could someone advise me on the correct syntax for highlighting if an email address includes a year of birth?

    So far I have created the following, the last line extracts the year of birth from the DOB field as YEAR_OF_BIRTH which I would like to see if it is included in the email address.

    SELECT

    CONVERT(DATE, (DOB)) AS DOB,

    EMAIL,

    LEFT(RIGHT(CONVERT(DATE, (DOB)),8),2) AS YEAR_OF_BIRTH

    FROM

    TABLE

    What I would like is a Yes/No entry in a field if the year of birth is included in the email address field - I'm not sure how I compare the 2 fields.

    Add something like this to your SELECT list?

    CASE WHEN EMAIL LIKE '%' + LEFT(RIGHT(CONVERT(DATE,(DOB)),8),2) + '%@%' THEN 'Yes' ELSE 'No' END AS DOBYearInEmail

    ...

    Thomas Rushton
    blog: https://thelonedba.wordpress.com