查看: 1136|回复: 3
|
帮个忙,有谁可以让这个SQL coding再简化一点??
[复制链接]
|
|
Private Sub cmdOK_Click()
Dim lot As String
Dim whno As String
Dim cna As String
Dim cnb As String
Dim sa As String
Dim pcode As String
SQL = "select LotNo, WHNo, CNA, CNB, SA ,Pcode from CnCBom where trim(Left(LotNo,11)) = " & " '" & Trim(cboLotNo) & "' and Status <> '' Group by LotNo, WHNo, CNA, CNB, SA ,Pcode"
Set rs = New ADODB.Recordset
rs.Open SQL, AdoConStr, adOpenDynamic, adLockOptimistic, adCmdText
Do While Not rs.EOF
With rs
lot = Trim(Left(!LotNo, 11))
If IsNull(Trim(!whno)) = False Then whno = Trim(!whno)
If IsNull(Trim(!cna)) = False Then cna = Trim(!cna)
If IsNull(Trim(!cnb)) = False Then cnb = Trim(!cnb)
If IsNull(Trim(!sa)) = False Then sa = Trim(!sa)
If IsNull(Trim(!pcode)) = False Then pcode = Trim(!pcode)
SQL = "select * from Sublot where LotNo = " & " '" & lot & "' and WHNo = " & " '" & whno & "' and CNA = " & " '" & cna & "' and CNB = " & " '" & cnb & "' and SA =" & " '" & sa & "' and Pcode = " & " '" & pcode & "'"
Set rs1 = New ADODB.Recordset
rs1.Open SQL, AdoConStr, adOpenDynamic, adLockOptimistic, adCmdText
If rs1.EOF Then
With rs1
.AddNew
!LotNo = lot
!whno = whno
!cna = cna
!cnb = cnb
!sa = sa
!pcode = pcode
.Update
End With
End If
End With
rs.MoveNext
Loop
MsgBox "Record aaaa successfully.", vbInformation + vbOKOnly, ""
End Sub
我写了这样的coding,行得通,得到我要的result,但是因为用loop,造成它run的时候好慢!!! 我run千多个records都要花上1mins左右,我的table最少都有几万个records哦。。。。, 怎么办?? 有人可以帮忙吗?? |
|
|
|
|
|
|
|
发表于 24-3-2005 09:01 AM
|
显示全部楼层
是 VB ?
可以要你的源代码 + DB 吗?
帮你试试看看
还有,不清楚你的目的,也是很难做“优化”。
几万笔记录,耗时间是难免的。 |
|
|
|
|
|
|
|
楼主 |
发表于 24-3-2005 09:56 AM
|
显示全部楼层
sson 于 24-3-2005 09:01 AM 说 :
是 VB ?
可以要你的源代码 + DB 吗?
帮你试试看看
还有,不清楚你的目的,也是很难做“优化”。
几万笔记录,耗时间是难免的。
谢谢你咯...,我后来才发现问题不出在这个form, 而是crystal report 里的+,-,*, / formula 太多了,再加上每一次要run几万个report,所以program陷入瘫痪状态!! 我再看看还有没有其他方法!! |
|
|
|
|
|
|
|
发表于 24-3-2005 11:10 AM
|
显示全部楼层
试看看
------------------------------------
SQL = “insert Into Sublot (LotNo, whno, cna, cnb, sa, pcode)”
SQL = SQL & “ Select CnCBom.LotNo, CnCBom.whno, CnCBom.cna, CnCBom.cnb, CnCBom.sa, CnCBom.pcode From CnCBom Left Join Sublot ”
SQL = SQL & “ On CnCBom!LotNo = Sublot!LotNo”
SQL = SQL & “ And CnCBom!whno = Sublot!whno”
SQL = SQL & “ And CnCBom!cna = Sublot!cna”
SQL = SQL & “ And CnCBom!cnb = Sublot!cnb”
SQL = SQL & “ And CnCBom!sa = Sublot!sa”
SQL = SQL & “ And CnCBom!pcode = Sublot!pcode”
SQL = SQL & “ Where trim(Left(LotNo,11)) = " & " '" & Trim(cboLotNo) & "' and Status <> ''
SQL = SQL & “ And Sublot!LotNo is Null”
SQL = SQL & “Group by CnCBom.LotNo, CnCBom.whno, CnCBom.cna, CnCBom.cnb, CnCBom.sa, CnCBom.pcode” |
|
|
|
|
|
|
| |
本周最热论坛帖子
|