两句sql脚本,用数据库工具运行,都是正常的,装到vba中就报错了 报错信息:运行时错误:3704 对象关闭时,不允许操作 正常的sql脚本,只是查询 报错的sql脚本,要将查询结果插入一个表,再从这个表中查询出数据
Workbooks("奋战120天中金所成交量.xlsx").Activate Worksheets("主界面").Activate StartDate = Range("i2").Value EndDate = Range("j2").Value
strSql01 = "INSERT INTO t_66666_registers" & vbNewLine & _ "SELECT '总权益',SUM(t_flex_cusfund.[期末权益])/10000000"
strSql02 = "FROM t_flex_cusfund" & vbNewLine & _ "WHERE t_flex_cusfund.[交易日] = '20200915'" & vbNewLine & _ "select * from t_66666_registers"
' strSql01 = "SELECT '总计',SUM(t_flex_cusfund.[期末权益])/10000000"
' strSql02 = "FROM t_flex_cusfund" & vbNewLine & _ "WHERE t_flex_cusfund.[交易日] = '20200916'"
sql = strSql01 & strSql02 cn.Open ServerConn cn.CommandTimeout = 600 rs.Open sql, cn
Workbooks("奋战120天中金所成交量.xlsx").Activate Worksheets("每日").Activate Range("A:aa").Clear Worksheets("每日").Range("A1").Select
Range("a1").CopyFromRecordset rs
|