0

I'm using a simple SQL query to get DAY, MONTH, YEAR out of a Date field (BIRTH_DATE) in Automation Studio (of marketing cloud).

SELECT 
  CUST_CODE
, EXCLUDED_FROM_NPS
, BIRTH_DATE
, DATEPART(DD,BIRTH_DATE) AS DAY_DOB
, DATEPART(MM,BIRTH_DATE) AS MONTH_DOB
, DATEPART(YYYY,BIRTH_DATE) AS YEAR_DOB
FROM Import_Customer_TH

When I validate the syntax, it gives the error

An error occurred while checking the query syntax. Errors: Old style JOIN (ANSI JOINs) syntax is not allowed. Please use standard syntax. _NPS, is not a known data extension or system data view. You can only query existing data extensions or system data views

I don't have any Joins in the query.
I tried this version too, but same error

 SELECT 
  CUST_CODE
, EXCLUDED_FROM_NPS
, BIRTH_DATE
, DAY(BIRTH_DATE) AS DAY_DOB
, MONTH(BIRTH_DATE) AS MONTH_DOB
, YEAR(BIRTH_DATE) AS YEAR_DOB
FROM Import_Customer_TH
2
  • Have you tried rename EXCLUDED_FROM_NPS column? the error looks like it confused Excluded_From_NPS with TSQL "From _NPS".
    – Bo Hu
    Dec 6, 2017 at 4:46
  • ahhhh!! interesting
    – sfdcFanBoy
    Dec 6, 2017 at 15:12

1 Answer 1

6

The SQL parser in SFMC is really dumb sometimes.

I'd recommend something like what @Bo Hu suggested, but just add brackets around it:

SELECT 
  CUST_CODE
, [EXCLUDED_FROM_NPS]
, BIRTH_DATE
, DATEPART(DD,BIRTH_DATE) AS DAY_DOB
, DATEPART(MM,BIRTH_DATE) AS MONTH_DOB
, DATEPART(YYYY,BIRTH_DATE) AS YEAR_DOB
FROM Import_Customer_TH

I did a quick test and this appears to work.

1
  • I was just getting this error "The __c table has been deleted and can no longer be used in a query." and adding the brackets fixed it. Thanks! Oct 12, 2020 at 15:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .