Solved

Reducing query results by using partial column words

Posted on 2012-03-27
7
273 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
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.

746 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

11 Experts available now in Live!

Get 1:1 Help Now