|
不知道是不是这个意思
你看看结果对不对
1 定义一个函数
- Public Function Gposition(Accor As Integer) As String
- Dim tempString As String
- Select Case Accor
- Case Is > 80
- tempString = "D"
- Case Is > 60
- tempString = "C"
- Case Is > 20
- tempString = "B"
- Case Else
- tempString = "A"
- End Select
- Gposition = tempString
- End Function
复制代码
2 随便做个查询,称之为“Q”
3 通过按钮事件来实现结果
- Private Sub Command2_Click()
- Dim rs As New ADODB.Recordset
- Dim Def As DAO.QueryDef
- Dim strSQL As String, sSQL As String
- Dim i As Integer
- Set Def = CurrentDb.QueryDefs("Q")
- For i = 20 To 100 Step 20
- strSQL = "select top " & i & " percent * from 商品 order by 销售数量 desc"
- Def.sql = strSQL
- sSQL = "select 分类 from q where 分类 is null"
- With rs
- .Open sSQL, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
- Do While Not .EOF
- If IsNull(.Fields(0)) Then
- .Fields(0) = i
- .MoveNext
- End If
- Loop
- .UpdateBatch
- .Close
- End With
- Next
- sSQL = "select 商品全名,销售数量,gposition(分类) as 新分类 from 商品 order by 销售数量 desc"
- Def.sql = sSQL
- DoCmd.OpenQuery "Q"
- Def.Close
- Set Def = Nothing
- Set rs = Nothing
- End Sub
复制代码 |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|