Helpful Information
 
 
Category: Delphi Programming
Replace function in ADOQuery/JET 4.0

Hi,

I'm running a query from a Delphi app on data stored in an Access 97 *.mdb using ADOQuery that searches for data using LIKE . The problem is, I need to be able to search for words without typing in the spaces.

For example - searching on '%alovelyday%'

would retrieve not only "alovelyday", but also "a lovely day", or even "alove lyday"

To do this I assumed I'd be able to use:



SELECT + FROM Table WHERE REPLACE(Column_Name, ' ', '') LIKE '%alovelyday%'


But my JET 4.0 driver returns the following error:

"undefined function 'replace()' in expression".

So it looks like I can't use this function and will have to do it another way.

So my question is.... can anyone think of another way of doing this? Can it be done with patternmatching? Is there a way of searching a string and telling the query to ignore whitespace?

Please help - this has been driving me insane! It should be so simple ....!

This was posted on

http://www.utteraccess.com/forums/showflat.php?Cat=&Board=access_97&Number=223288





Public Function fReplace(ByVal ValueIn As String, ByVal WhatToReplace As String, ByVal ReplaceValue As String) As String

Dim Temp As String
Dim P As Long

Temp = ValueIn
P = InStr(Temp, WhatToReplace)
Do While P > 0
Temp = Left(Temp, P - 1) & ReplaceValue & Mid(Temp, P + Len(WhatToReplace))
P = InStr(P + Len(ReplaceValue), Temp, WhatToReplace, 1)
Loop
fReplace = Temp

End Function










privacy (GDPR)