• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 281
  • Last Modified:

Reducing query results by using partial column words

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
jsawicki
Asked:
jsawicki
3 Solutions
 
Rey Obrero (Capricorn1)Commented:
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
 
Dale FyeCommented:
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
 
Jeffrey CoachmanCommented:
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
Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 
jsawickiAuthor Commented:
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
 
Rey Obrero (Capricorn1)Commented:
in access you will use "*" asterisk in a query

you can use "%" when you are dealing with ADODB recordsets using  VBA codes
0
 
jsawickiAuthor Commented:
Thanks all
0
 
HainKurtSr. System AnalystCommented:
% 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now