I'm getting the missing right parenthesis error on this query. What am I missing here, I see 5 left and 5 right parenthesis. What I'm trying to do is to only return rows with the most current date.
WITH snCTE AS
(
SELECT
T1.column1
,T1.column2
,T2.column3
,T2.column4
,T1.datefield
,ROW_NUMBER() OVER (PARTITION BY column1 ORDER BY datefield DESC) AS RN
FROM dBtable1 T1
LEFT OUTER JOIN dBtable2 T2 ON (T1.columnid=T2.columnid AND T1.otherfield=T2.otherfield)
WHERE EXISTS (SELECT 1 FROM dbtable3 AS T3 WHERE T3.column1 = T1.column1)
)
SELECT column1, column2, column3, column4, datefield
FROM snCTE
WHERE snCTE.RN = 1