简体   繁体   中英

VBA ADODB Connection -SQL QUERY

I am Running in VBA But same is not working. Getting error no Value Given for one or more Required Parameter.

My Query :

esql = "Select MAPPING_MONTH.DT,SUM(MAIL_ACTIVE_Base_Tracker_GA_AM_AO.COUNT) as GA_COUNT From MAPPING_MONTH A LEFT OUTER JOIN MAIL_ACTIVE_Base_Tracker_GA_AM_AO B on A.DT=B.DATE where ((MAIL_ACTIVE_Base_Tracker_GA_AM_AO.CIRCLE)= " & """" & FName & "GROUP BY MAIL_ACTIVE_Base_Tracker_GA_AM_AO.CIRCLE"")"

RS.Open (esql), CN, adOpenStatic, adLockReadOnly

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:

  1. Remove the brackets around esql in the RS.Open line.
  2. Remove the brackets inside the constructed T-SQL statement
  3. Exchange the " inside your T-SQL for ' to include the file name as text.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM