by Khalid Sweese (1 Submission)
Category: Databases/Data Access/DAO/ADO
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Wed 10th October 2001
Date Added: Mon 8th February 2021
Rating:
(1 Votes)
If you want to get the SQL Statement that describes comma seperated value or a range of values or both ... Like you want the owners of account
'Khalid Sweeseh ([email protected])
'www.Globitel.com
On Error GoTo ErrH
Dim StringCollection As Collection
Dim strBetweenSQL As String
Dim strBTWNOp As String
Dim strINOp As String
Dim strInSQL
Dim i As Integer
i = 1
i = InStr(i, strIn, ",")
Set StringCollection = New Collection
While i > 0
StringCollection.Add Mid(strIn, 1, i - 1)
strIn = Mid(strIn, i + 1)
i = InStr(1, strIn, ",")
Wend
StringCollection.Add strIn
For i = 1 To StringCollection.Count
If InStr(StringCollection.Item(i), "-") Then
strBetweenSQL = strBetweenSQL & strBTWNOp & "% Between '" & Replace(StringCollection.Item(i), "-", "' And '") & "'"
strBTWNOp = " OR "
Else
strInSQL = strInSQL & strINOp & "'" & StringCollection.Item(i) & "'"
strINOp = ","
End If
Next i
strBetweenSQL = Replace(strBetweenSQL, "%", FieldName)
If Len(strInSQL) Then strInSQL = FieldName & " In (" & strInSQL & ")"
SepStringtoSQL = strBetweenSQL & IIf(Len(strInSQL) > 0 And Len(strBetweenSQL) > 0, " OR ", "") & strInSQL
Exit Function
ErrH:
MsgBox Err.Description
End Function
No comments have been posted about If you want to get the SQL Statement that describes comma seperated value or a range of values or b. Why not be the first to post a comment about If you want to get the SQL Statement that describes comma seperated value or a range of values or b.