--------- SQL generation ----------
The task is to use In (X, Y) when the user is separated by a comma, using IN (x, y), but when the field corresponding to the database is a character pattern, it will have an error, that is of course! If it is in ('x', 'y') there is no problem!
The following code is the operation of the string, returns 'x', 'y'.
'----- Accept the string to be processed -------
Function Tool_Distest (ByVal Textbefore as String)
DIM textAfter () AS String
DIM INTNUM, INTEXTLEN, K, I AS Integer
INTNUM = 1
INTTEXTLEN = LEN (TextBefore)
'-------- How much query conditions are calculated --------
For i = 1 to inttextlen
IF MID (TextBefore, I, 1) = "," THEN
INTNUM = INTNUM 1
END IF
NEXT
'-----------------------------------
Redim textAfter (intNum)
K = 1
'-------- put each condition in an array ---------
For i = 1 to inttextlen
IF MID (TextBefore, I, 1) = "," THEN
K = 1
Else
TextAfter (k) = TextAfter (K) & Mid (TextBefore, i, 1)
END IF
NEXT
'----------------------
DIM STRTEMP AS STRING
'-------- To each of the conditions ----------
For i = 1 to intnum
Strtemp = TextAfter (i)
TextAfter (i) = "'" & strtemp & "'"
NEXT
'----------------------
strTemp = ""
'------ Add separation conditions "," ------
For i = 1 to intnum
Strtemp = STRTEMP & TEXTAFTER (I) & ","
NEXT
'------------------
'------ Remove the last one, ------
Strtemp = MID (Strtemp, 1, Len (Strtemp) - 1)
'-------------------
Return strTemp
END FUNCTION
Finally, I tried it in SQL Server. When I found that SQL Server queries, I used in (x, y) to query the characters OK, (SQL Server is better than Access "
,Ha ha)
--------- End -------