Supportnet / Forum / Datenbanken
IP Sortieren
Frage
Kennst jemand ein Beispiel welche IP Nummern richtig sortiert?
Beispiel:
192.168.0.1
192.168.0.15
192.168.0.049
192.168.0.50
192.168.0.51
192.168.0.151
u.s.w.
Antwort 1 von struppi
hallo
Du könntest die Zahlen
3 stellig abspeichern dann müsste die sortierung ja klappen.
zB 192.168.000.001
Bei Bedarf die Zahl umwandeln.
Oder jede Zahl in eine eigene Tabellenspalte schreiben und Zusammenführen mit einem Ausdruck in einer Abfrage. Was besseres fällt MIR jetzt nicht ein.
Du könntest die Zahlen
3 stellig abspeichern dann müsste die sortierung ja klappen.
zB 192.168.000.001
Bei Bedarf die Zahl umwandeln.
Oder jede Zahl in eine eigene Tabellenspalte schreiben und Zusammenführen mit einem Ausdruck in einer Abfrage. Was besseres fällt MIR jetzt nicht ein.
Antwort 2 von Rainer Stocher
Versuchs mal damit:
Function IP_Format(IPADR As Variant) As String
Dim strMask
Dim x
Dim anzPunkt
IP_Format = "000.000.000.000"
If IsNull(IPADR) Then Exit Function
If IPADR = "" Then Exit Function
IP_Format = ""
strMask = ""
anzPunkt = 0
For x = 1 To Len(IPADR)
If IsNumeric(Mid(IPADR, x, 1)) Then strMask = strMask & Mid(IPADR, x, 1)
If Mid(IPADR, x, 1) = "." Then
anzPunkt = anzPunkt + 1
IP_Format = IP_Format & Format(strMask, "000")
If anzPunkt <= 3 Then IP_Format = IP_Format & "."
strMask = ""
End If
Next x
IP_Format = IP_Format & Format(strMask, "000")
End Function
Diese Function kannst Du dann z.B. in einer Abfrage verwenden:
SELECT IP_Format([IP]) AS IP
FROM Tabelle
ORDER BY IP_Format([IP]);
greeting rainer
Function IP_Format(IPADR As Variant) As String
Dim strMask
Dim x
Dim anzPunkt
IP_Format = "000.000.000.000"
If IsNull(IPADR) Then Exit Function
If IPADR = "" Then Exit Function
IP_Format = ""
strMask = ""
anzPunkt = 0
For x = 1 To Len(IPADR)
If IsNumeric(Mid(IPADR, x, 1)) Then strMask = strMask & Mid(IPADR, x, 1)
If Mid(IPADR, x, 1) = "." Then
anzPunkt = anzPunkt + 1
IP_Format = IP_Format & Format(strMask, "000")
If anzPunkt <= 3 Then IP_Format = IP_Format & "."
strMask = ""
End If
Next x
IP_Format = IP_Format & Format(strMask, "000")
End Function
Diese Function kannst Du dann z.B. in einer Abfrage verwenden:
SELECT IP_Format([IP]) AS IP
FROM Tabelle
ORDER BY IP_Format([IP]);
greeting rainer

