Solved

Reducing query results by using partial column words

Posted on 2012-03-27
7
278 Views
Last Modified: 2012-03-27
Below is my functional SQL, but every time i try to use the Like function to retrieve results in a field that contain a specific set of words, it returns no data.  Fields JOBTITLE & JOBCODE have words that contain APS and CPS and I want to retrieve only those fields.  In some instances it is at the beginning and independent whereas other times it is integrated into the name.  I thought it could be as simple as adding Like '%APS%' or '%CPS%' but anything i do, the query results are completely empty.  

Below are some examples of the data in that field:  APS Unit-M, Aps Gen/Fac Inves-M, CVSCPS01, INVCPS10, CPS Investigations


SELECT employeeinfo.LOGNAME, [First_Name] & " " & [Last_Name] AS EmployeeName, dragon.LastUser, dragon.TotalDuration, dragon.TimesRun, employeeinfo.DEPTNAME, employeeinfo.JOBTITLE, employeeinfo.JOBCODE, employeeinfo.REGION
FROM dragon INNER JOIN employeeinfo ON dragon.LastLoginName=employeeinfo.LOGNAME
WHERE (((dragon.LastUser) Is Not Null));
0
Comment
Question by:jsawicki
[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
7 Comments
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 200 total points
ID: 37773071
use a where clause like this

where JOBTITLE Like "*APS*" or JOBTITLE like "*CPS*"

you have to repeat the Field name

or


where JOBTITLE Like "%APS%" or JOBTITLE like "%CPS%"
0
 
LVL 48

Assisted Solution

by:Dale Fye (Access MVP)
Dale Fye (Access MVP) earned 150 total points
ID: 37773075
In Access, you need to use an asterisk "*" to represent multiple characters, not a percent sign.  So the SQL might look like:

SELECT employeeinfo.LOGNAME
          , [First_Name] & " " & [Last_Name] AS EmployeeName
          , dragon.LastUser
          , dragon.TotalDuration
          , dragon.TimesRun
          , employeeinfo.DEPTNAME
          , employeeinfo.JOBTITLE
          , employeeinfo.JOBCODE
          , employeeinfo.REGION
FROM dragon INNER JOIN employeeinfo
ON dragon.LastLoginName=employeeinfo.LOGNAME
WHERE dragon.LastUser Is Not Null
AND (employeeinfo.JOBTITLE Like "*APS*"
OR employeeinfo.JOBTITLE Like "*CPS*")
0
 
LVL 74

Assisted Solution

by:Jeffrey Coachman
Jeffrey Coachman earned 150 total points
ID: 37773090
You never posted what you tried?

Typically it might be something like this:

SELECT employeeinfo.LOGNAME, [First_Name] & " " & [Last_Name] AS EmployeeName, dragon.LastUser, dragon.TotalDuration, dragon.TimesRun, employeeinfo.DEPTNAME, employeeinfo.JOBTITLE, employeeinfo.JOBCODE, employeeinfo.REGION
FROM dragon INNER JOIN employeeinfo ON dragon.LastLoginName=employeeinfo.LOGNAME
WHERE JOBTITLE Like "*APS*"
0
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.

 

Author Comment

by:jsawicki
ID: 37773202
Boag2000, your right i should have posted what code i was using since it worked like a charm using the asterick.  However, when i inputted the % (as seen below) it returned no results.  What is the difference between * and % with the like statement.  

SELECT employeeinfo.LOGNAME, [First_Name] & " " & [Last_Name] AS EmployeeName, dragon.LastUser, dragon.TotalDuration, dragon.TimesRun, employeeinfo.DEPTNAME, employeeinfo.JOBTITLE, employeeinfo.JOBCODE, employeeinfo.REGION
FROM dragon INNER JOIN employeeinfo ON dragon.LastLoginName = employeeinfo.LOGNAME
WHERE (((dragon.LastUser) Is Not Null) AND ((employeeinfo.DEPTNAME) Like "%APS%"));
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 37773240
in access you will use "*" asterisk in a query

you can use "%" when you are dealing with ADODB recordsets using  VBA codes
0
 

Author Comment

by:jsawicki
ID: 37773292
Thanks all
0
 
LVL 55

Expert Comment

by:Huseyin KAHRAMAN
ID: 37773366
% is used in sql server and some other db
* is used in access for same purposes

see: http://www.techonthenet.com/access/queries/like.php
0

Featured Post

Independent Software Vendors: 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

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

688 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