Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Convert search string to SQL query

Posted on 2008-06-21
5
Medium Priority
?
164 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 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 1000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Recursive SQL is one of the most fascinating and powerful and yet dangerous feature offered in many modern databases today using a Common Table Expression (CTE) first introduced in the ANSI SQL 99 standard. The first implementations of CTE began ap…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

876 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