|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册账号
×
VBA代码- Sub 按钮1_单击()
- Dim conn As New ADODB.Connection
- Dim rst As ADODB.Recordset
- Dim constr As String
- Dim sql As String
- Dim bm As String
- Dim i, j
- On Error Resume Next
- constr = "Provider = SQLOLEDB;Data Source =JIN;Initial Catalog =UFDATA_666_2013;User ID =sa;Password =jin1668;"
- conn.Open (constr)
- Range("a6:j5000").ClearContents
- Randomize
- s = Int(Rnd * 10000 + 1000)
- ds = "NBUF_TmpReportA" & s
- bm = Trim(Range("b1"))
- If Len(bm) = 0 Then
- Exit Sub
- End If
- sql = "select a.cinvname,a.cinvstd,b.cComUnitName from inventory a left join ComputationUnit b on a.cComUnitCode =b.cComunitcode where a.cinvcode='" & bm & "'"
- Set rst = conn.Execute(sql)
- If rst.BOF = 0 Then
- Range("b2") = rst.Fields(0)
- Range("b3") = rst.Fields(1)
- Range("b4") = rst.Fields(2)
- Else
- MsgBox "不存在的存货编码!"
- Exit Sub
- End If
- Range("e1") = Time()
- [color=Red]sql = "exec Usp_BO_ExpandByComp 'and 1=1 And ((c.InvCode >= ''" & bm & "'') And (c.InvCode <= ''" & bm & "''))'," & " '" & "2099-12-04" & "', 0, 0, 3, 0, 0, 0,1,'', '','" & ds & " '"
- conn.Execute (sql)[/color]
- Range("e2") = Time()
- sql = "select 级别,子件行号,母件编码,母件名称,PItemSpec,母件计量单位,版本代号,版本说明,母件属性,基本用量 from " & ds
- Set rst = conn.Execute(sql)
- Range("e3") = Time()
- Cells(6, 1).CopyFromRecordset rst
- sql = "drop table " & ds
- conn.Execute (sql)
- rst.Close
- rst2.Close
- conn.Close
- Set rst = Nothing
- Set rst2 = Nothing
- Set conn = Nothing
- End Sub
复制代码
红色部门运行效率很慢,700多条母件记录要28秒,而用友系统只要2秒,,应该都是用的这个存储过程,这是那么回事,请高手指点? |
|