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

x
?
Solved

Using LIKE and OR to look for more then one pattern in a field

Posted on 2009-04-03
2
Medium Priority
?
221 Views
Last Modified: 2013-11-28
Hi all this is probably pretty simple but I dont work in SQL but 4gl

I have a sql statement that uses like to find entries that contain the term 'out' for a particular date range.

What I want to do is specify that I want to look for entries that contain the word 'out' OR 'in' OR 'pto'.

Looking at the code example below how would I change this with the following select statement.
Original working query:
 
query = "SELECT * FROM cal_events E INNER JOIN cal_dates D" _
	& " ON (E.event_id = D.event_id) " _
	& " WHERE (event_title LIKE '%out%') AND (event_date BETWEEN #" & Date & "# AND #" & Date & "#) AND (user_id = " _
	& Session(dataName & "User") & " OR " _
	& "private = 0) ORDER BY event_date"
 
 
I tried changing to:
 
query = "SELECT * FROM cal_events E INNER JOIN cal_dates D" _
	& " ON (E.event_id = D.event_id) " _
	& " WHERE (event_title LIKE '%out%') OR " _
	& "(event_title LIKE '%in%') & OR " _
	& "(event_title LIKE '%pto%') & AND " _ 
	& "(event_date BETWEEN #" & Date & "# AND #" & Date & "#) AND (user_id = " _
	& Session(dataName & "User") & " OR " _
	& "private = 0) ORDER BY event_date"
	
OR can I use a wild card to simplify something like:
 
query = "SELECT * FROM cal_events E INNER JOIN cal_dates D" _
	& " ON (E.event_id = D.event_id) " _
	& " WHERE (event_title LIKE '[out,in,pto]%') AND (event_date BETWEEN #" & Date & "# AND #" & Date & "#) AND (user_id = " _
	& Session(dataName & "User") & " OR " _
	& "private = 0) ORDER BY event_date"

Open in new window

0
Comment
Question by:binovpd
2 Comments
 
LVL 17

Accepted Solution

by:
k_murli_krishna earned 200 total points
ID: 24063034
The first one you changed to is correct. Once cannot use as OR operator in a group for LIKE operator the way you do for IN operator. Since your words are part of bigger words/phrases/sentences you need to use LIKE and each LIKE separated by OR.
0
 

Author Closing Comment

by:binovpd
ID: 31566378
Thanks k_murli_krishna I got it to work.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

927 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