Solved

Reducing query results by using partial column words

Posted on 2012-03-27
7
274 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 119

Accepted Solution

by:
Rey Obrero 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

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 119

Expert Comment

by:Rey Obrero
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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

895 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now