<% \'Function GetSQLSearchString(Str As String, Records As String) As String Function GetSQLSearchString(Str, Records) Do While CBool(InStr(1, Str, \"( \")) Or CBool(InStr(1, Str, \" )\")) Or CBool(InStr(1, Str, \" \")) Str = Replace(Str, \" )\", \")\") Str = Replace(Str, \"( \", \"(\") Str = Replace(Str, \" \", \" \") Loop
\' Dim bExp As Boolean, BoolStop As Boolean, i As Integer, nStr As String, strExp As String, BoolStart As Boolean
bExp = False BoolStop = False Str = Str & \" \" For i = 1 To Len(Str) s = Mid(Str, i, 1) If s = Chr(34) Then bExp = Not bExp If s = \" \" Then If Not bExp Then If strExp <> \"\" Then If nStr = \"\" Then nStr = strExp t = UCase(strExp) If (CBool(InStr(1, t, \"AND\")) Or CBool(InStr(1, t, \"OR\")) Or CBool(InStr(1, t, \"NOT\"))) Then BoolStart = True Else t = UCase(strExp) If Not ((t = \"AND\") Or (t = \"OR\") Or (t = \"NOT\")) Then If BoolStop Or BoolStart Then nStr = nStr & \" \" & strExp & \" \" BoolStop = False BoolStart = False Else nStr = nStr & \" AND \" & strExp & \" \" End If Else BoolStop = True nStr = nStr & \" \" & t & \" \" End If End If End If strExp = \"\" Else strExp = strExp & \" \" End If Else strExp = strExp & s End If Next nStr = nStr & strExp nStr = Replace(nStr, \" \", \" \") Str = Replace(nStr, \"\'\", \"\")
\' Dim ReplExp As String, rec() As String
If InStr(1, Records, \",\") Then rec = Split(Records, \",\") ReplExp = \"(\" For i = 0 To UBound(rec) ReplExp = ReplExp & \"(\" & rec(i) & \" LIKE \'%<exp>%\')\" If i <> UBound(rec) Then ReplExp = ReplExp & \" OR \" Else ReplExp = ReplExp & \")\" End If Next Else ReplExp = \"(\" & Records & \" = \'<exp>\')\" End If
\' Dim SQLSearch As String, ParanWritten As Boolean
ParanWritten = False bExp = False SQLSearch = \"\" If InStr(1, Str, \" \") Then For i = 1 To Len(Str) s = Mid(Str, i, 1) If s = Chr(34) Then bExp = Not bExp If (s = \"(\") Or (s = \")\") Or (s = \" \") Or (s = Chr(34)) Then If Not bExp Then If strExp <> \"\" Then t = UCase(strExp) If (t = \"AND\") Or (t = \"OR\") Or (t = \"NOT\") Then SQLSearch = SQLSearch & \" \" & t & \" \" Else SQLSearch = SQLSearch & Replace(ReplExp, \"<exp>\", strExp) End If strExp = \"\" SQLSearch = SQLSearch & s Else If (s = \"(\") Then SQLSearch = SQLSearch & \"(\" ParanWritten = True End If End If Else strExp = strExp & \" \" End If Else If s <> Chr(34) Then strExp = strExp & s End If Next Else SQLSearch = Replace(ReplExp, \"<exp>\", Str) End If
Do While InStr(1, SQLSearch, \" \") SQLSearch = Replace(SQLSearch, \" \", \" \") Loop
Do While CBool(InStr(1, SQLSearch, \"% \")) Or CBool(InStr(1, SQLSearch, \" %\")) SQLSearch = Replace(SQLSearch, \"% \", \"%\") SQLSearch = Replace(SQLSearch, \" %\", \"%\") Loop
SQLSearch = Replace(SQLSearch, Chr(34), \"\")
SQLSearch = Trim(SQLSearch) If UCase(Left(SQLSearch, 2)) = \"OR\" Then SQLSearch = Right(SQLSearch, Len(SQLSearch) - 2) If UCase(Left(SQLSearch, 3)) = \"AND\" Then SQLSearch = Right(SQLSearch, Len(SQLSearch) - 3)
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.