Solved

Reducing query results by using partial column words

Posted on 2012-03-27
7
276 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
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 47

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
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 

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 51

Expert Comment

by:HainKurt
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
update query 4 25
table joins in qry 17 61
Access 2010 change CurrentUser 5 33
record saved form with no buttons or X 3 20
This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

856 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