|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
sql语句不知道怎么实现一个表格动态实现另一个汇总表格累加,各位大神看下写的语句有什么错误,试了几个语句都实现不了
Sub DoSql()
Dim cnn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim Sql As String
Dim i, j
cnn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties=Excel 12.0;Data Source=" & ThisWorkbook.FullName
Sql = "UPDATE [计件表$] set 数量=sum(数量) where [添加表$].姓名=[计件表$].姓名" '数量累加,按姓名统计
j = Range("a1000").End(xlUp).Row
For i = 2 To j
n = Cells(i, 4)
m = Cells(i, 1)
Sql = "UPDATE [计件表$] SET 数量= 数量 +" & n & " where 姓名= '" & m & "'" '数量累加,按姓名统计
'Sql = "UPDATE [计件表$] SET 工资= 工资 + 200 where 姓名='看见星光'"
'Sql = "update [计件表$] set 性别= '男', 工龄= 8 where 姓名= '仓井'"
Next
rs.Open Sql, cnn, adOpenKeyset, adLockOptimistic
cnn.Close
Set rs = Nothing
Set cnn = Nothing
End Sub
|
|