I have a query in teradata where i am trying to get the week number from a specific date in the format yyyymmdd (20160201). We have a calendar table (not the teradata one because we count weeks slightly differently) which allows you to join the date and export the results
When i run the query with static dates so for the example below runs fine
FROM table_main AL1
JOIN cal_table cal
ON AL1.run_date = cal.cal_dateyyyymmdd
WHERE AL1.run_date >= 20160201
AND AL1.run_date < 20160220
When i try to generalize the statement to the previous week
FROM table_main AL1
JOIN cal_table cal
ON AL1.run_date = cal.cal_dateyyyymmdd
WHERE AL1.run_date >= CAST(CAST(((DATE-DAYOFWEEK(DATE)-5) (FORMAT 'YYYYMMDD')) AS CHAR(8)) AS INT)
AND AL1.run_date < CAST(CAST(((DATE-DAYOFWEEK(DATE)+ 1) (FORMAT 'YYYYMMDD')) AS CHAR(8)) AS INT)
I get the error
SELECT Failed. 3706: Syntax error: expected something between ')' and '-'.
Has anyone ever seen this before?