While there is some code missing which could be helpful in debugging the code here are some improvements which (potentially) already resolve your problem. If that's not the case then you might want to consider updating your post and include more of your code (where you declare RS and CN and setup the ADODB.Connection).
Having said that here are the suggested changes:
esql = " select MAPPING_MONTH.DT, "
esql = esql & " sum(MAIL_ACTIVE_Base_Tracker_GA_AM_AO.COUNT) as GA_COUNT "
esql = esql & "from MAPPING_MONTH A "
esql = esql & "left outer join MAIL_ACTIVE_Base_Tracker_GA_AM_AO B "
esql = esql & "on A.DT = B.DATE "
esql = esql & "where MAIL_ACTIVE_Base_Tracker_GA_AM_AO.CIRCLE = N'" & FName & "' "
sql = esql & "group by MAIL_ACTIVE_Base_Tracker_GA_AM_AO.CIRCLE "
RS.Open esql, CN, adOpenStatic, adLockReadOnly
Changes:
- Remove the brackets around
esql in the RS.Open line.
- Remove the brackets inside the constructed T-SQL statement
- Exchange the
" inside your T-SQL for ' to include the file name as text.
"""" & FName & "GROUP BY MAIL_ACTIVE_Base_Tracker_GA_AM_AO.CIRCLE"")"... you need a space betweenFNameandGROUP BY.