I am creating this SQL query in Automation Studio. This query gives me an error:
An error occurred while checking the query syntax. Errors: Error while parsing query. Please check the syntax
When adding the last AND statement the error shows. Here's my querycode:
SELECT x.Email, x.Country, x.First_Name, x.Date_of_Birth, x.Age,
CASE
WHEN Country IN ('US', 'CA') THEN 'NA'
WHEN Country IN ('DE', 'FR', 'GB', 'DK', 'FI', 'SE', 'AT', 'PL', 'PT', 'NO', 'NL', 'IE', 'BE') THEN 'EU'
ELSE 'ASIA'
END as Region
, datediff(day, getdate(), x.nextBirthDay) AS 'Days_Before_Birthday'
FROM
(
SELECT
a.Email
, a.Date_Of_Birth
, a.First_Name
, datediff(year,a.Date_Of_Birth, getDate()) as 'Age'
, CASE
WHEN (dateadd(year,datediff(year,a.Date_Of_Birth,getDate()), a.Date_Of_Birth) > getDate()) THEN dateadd(Year,datediff(year,a.Date_Of_Birth,getDate()), a.Date_Of_Birth)
ELSE dateadd(year, datediff(year,a.Date_Of_Birth,getDate())+1 , a.Date_Of_Birth)
END as nextBirthDay
from [Master DB] a
where a.Date_Of_Birth is not null
) x
WHERE
datediff(day, getdate(), x.nextBirthDay) <= 1
AND x.Email NOT IN(Select Email FROM [Welcome_Journey_Exclusion DE])
AND x.Country IN ('GB','US','CA','DK', 'DE','FR','SG','HK', 'FI', 'SE', 'AU', 'IE', 'BE', 'NL', 'NO', 'PT', 'PL', 'AT')
Thank you in advance.