Solved

Convert search string to SQL query

Posted on 2008-06-21
5
153 Views
Last Modified: 2010-04-30
Hi Experts

I'd like to create a query out of a comma delimited "search string"
egSearchstring =  "Item1, Item2, Item3........."
to
sql = sql & "where [Data] like '*Item1*' or [Data] like '*Item2*' or [Data] like '*Item3*' "

I'm thinking of converting "searchstring"  into a "sql string" and then writing
sql = sql & sqlstring

Your ideas on creating that "sql string" would be much appreciated. ( Working in VB6)

Many thanks

Peter

0
Comment
Question by:peterdarazs
  • 3
  • 2
5 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 21837042
here we go:
egSearchstring =  "Item1,Item2,Item3........." 
sql = sql & "where [Data] like '*" & join( split(egsearchString, ","), *' or [Data] like '*" ) & "*' "

Open in new window

0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 250 total points
ID: 21837043
a small correction
egSearchstring =  "Item1,Item2,Item3........." 
sql = sql & "where [Data] like '*" & join( split(egsearchString, ","), "*' or [Data] like '*" ) & "*' "

Open in new window

0
 

Author Closing Comment

by:peterdarazs
ID: 31469397
Thanks Angellll

This looks like the solution. I'm a little confused as to the second 'or [Data]' in the routine , but assume this will join to each split item to anothe 'or [Data]' as if it were hard coded. If this is the case , then 100% and complete solution . many thanks

Please let me know if my assumption was incorrect though....

Thanks again

Peter
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 21837180
<Grading Comments>
Thanks Angellll

This looks like the solution. I'm a little confused as to the second 'or [Data]' in the routine , but assume this will join to each split item to anothe 'or [Data]' as if it were hard coded. If this is the case , then 100% and complete solution . many thanks

Please let me know if my assumption was incorrect though....

Thanks again

Peter
</Grading Comments>

the first
sql = sql & "where [Data] like '*"
is for the first search item

the join is for what comes between the search items:
join(xxxx , "*' or [Data] like '*" )

and finally:
& "*' "

is to close the last item (which would be the first item if there was only one item)
0
 

Author Comment

by:peterdarazs
ID: 21837284
Ok , that's perfect then, and apprecaite the explanation.

Enjoy your day.
Peter

0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now