|
sub jj()
Dim cnn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim i, sql, stsql
On Error GoTo errmsg
cnn.Open "provider=microsoft.jet.oledb.4.0;extended properties='Excel 8.0;imex=2';data source=" & ThisWorkbook.FullName
stsql = "select B.合同编号,B.验收时间 from B Where B.合同编号 Is not Null and B.施工阶段='已验收' "
'将 上句修改为: stsql = "select B.合同编号,first(B.验收时间) as 验收时间 from B Where B.合同编号 Is not Null and B.施工阶段='已验收' group by B.合同编号 " 或修改为 stsql = "select distinct B.合同编号,B.验收时间 from B Where B.合同编号 Is not Null and B.施工阶段='已验收' " 为什么就提示:操作必须使用一个可以更新查询?如何修改
sql = "update A,(" & stsql & ") as B set A.验收时间 =B.验收时间 where A.合同编号=B.合同编号"
cnn.Execute sql '不判断,更新可能存在的“合同编号”
cnn.Close
Set rs = Nothing
Set cnn = Nothing
END Exit Sub
|
|