Solved

Convert search string to SQL query

Posted on 2008-06-21
5
159 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 143

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 143

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 143

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

'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 …
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month9 days, 9 hours left to enroll

624 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