tranthanhan1962 > 21-07-15, 12:31 AM
Function XepHang(TenQuery As String, FieldXepHang As String, FieldID As String, ValueID, Kieuxep As Integer) As String
On Error GoTo BiLoi
Dim CSDL As Database
Dim Bang As Recordset
Dim Duocxephang As Long
Dim Xep As Double
Dim TrungHang As Double
Xep = 1
TrungHang = 0
Set CSDL = CurrentDb
Set Bang = CSDL.OpenRecordset(TenQuery, dbOpenDynaset, dbReadOnly)
Bang.FindFirst FieldID & " = " & ValueID
If Is_Null(Bang(FieldXepHang)) Then Exit Function
Duocxephang = Bang(FieldXepHang)
Bang.MoveFirst
Select Case Kieuxep
Case 0 ' Lon hang cao
Do Until Bang.EOF
If Bang(FieldXepHang) > Duocxephang Then Xep = Xep + 1
If Bang(FieldXepHang) = Duocxephang Then TrungHang = TrungHang + 1
Bang.MoveNext
Loop
If TrungHang > 1 Then
XepHang = Xep & "="
Else
XepHang = Xep
End If
Bang.Close
Set Bang = Nothing
Set CSDL = Nothing
Case 1 ' Nho hang cao
Do Until Bang.EOF
If Bang(FieldXepHang) < Duocxephang Then Xep = Xep + 1
If Bang(FieldXepHang) = Duocxephang Then TrungHang = TrungHang + 1
Bang.MoveNext
Loop
If TrungHang > 1 Then
XepHang = Xep & "="
Else
XepHang = Xep
End If
Bang.Close
Set Bang = Nothing
Set CSDL = Nothing
Case Else
End Select
BiLoi:
End Function
SELECT DiemHocTap.ID, XepHang("BangXepHangHocTap","Diem","ID",[ID],0) AS ThuHang, DiemHocTap.TenHS, DiemHocTap.Diem
FROM DiemHocTap
ORDER BY DiemHocTap.Diem;
tracanhtam > 21-07-15, 07:47 AM
tranthanhan1962 > 21-07-15, 11:37 AM
bvchauthanh > 23-07-15, 12:11 AM
maidinhdan > 23-07-15, 12:25 AM