先看图说话
[attach]38882[/attach]
小弟想根据积压时间,将表里的说自动划分,然后自动算出奖金
这步现在我已经实现了,但是问题在于:
不同的代码,奖金的比率不同,比如1开头的代码,奖金比率分别是0.1、0.2、0.3
2开头代码的比率是0.2、0.3、0.4
因此我的代码如下:
Private Sub cmdCalculate_Click()
Dim strSQL As String
If Not IsNull(Me.cboTableName) Then
If Left(代码, 1) = 1 Then
strSQL = "UPDATE " & Me.cboTableName & " INNER JOIN 计算标准1 ON [@Table].积压时间 = 计算标准1.积压时间 SET [@Table].划分 = [划分标准],[@Table].奖金 =[@Table].单价*[比率];"
strSQL = Replace(strSQL, "@Table", Me.cboTableName)
ElseIf Left(代码, 1) = 2 Then
strSQL = "UPDATE " & Me.cboTableName & " INNER JOIN 计算标准2 ON [@Table].积压时间 = 计算标准2.积压时间 SET [@Table].划分 = [划分标准],[@Table].奖金 =[@Table].单价*[比率];"
strSQL = Replace(strSQL, "@Table", Me.cboTableName)
End If
Debug.Print strSQL
CurrentProject.Connection.Execute strSQL
Me.fsubQuery.Requery
MsgBox "成功"
End If
End Sub
可是这样以来就总是提示出错,麻烦各位大哥给看看吧,是不是我的left函数的格式不对?
谢谢了!!!作者: Ombre 时间: 2009-7-15 21:24
Private Sub cmdCalculate_Click()
Dim strSQL1, strsql2 As String
If IsNull(Me.cboTableName) Then Exit Sub
strSQL1 = " UPDATE " & Me.cboTableName & " SET " & _
" 划分 = Switch([积压时间] Like '*1-10*','D1-D2',[积压时间] Like '*11-20*','D2-D3',[积压时间] Like '*21-30*','D3-D4')," & _
" 奖金 = Switch([积压时间] Like '*1-10*',[单价]*0.2,[积压时间] Like '*11-20*',[单价]*0.3,[积压时间] Like '*21-30*',[单价]*0.4) where " & "Left([代码], 1) =1"
strsql2 = " UPDATE " & Me.cboTableName & " SET " & _
" 划分 = Switch([积压时间] Like '*1-10*','D1-D2',[积压时间] Like '*11-20*','D2-D3',[积压时间] Like '*21-30*','D3-D4')," & _
" 奖金 = Switch([积压时间] Like '*1-10*',[单价]*0.2,[积压时间] Like '*11-20*',[单价]*0.3,[积压时间] Like '*21-30*',[单价]*0.4) where " & "Left([代码], 1) =2"