473,626 Members | 3,183 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Query problem

22 New Member
I have 2 tables in my query. M_Employees and M_Notes

M_Employees
empSSN - number, pk
empLastName - text
etc.

M_Notes
notesID - autonumber, pk
notesSSN - number, linked to SSN in M_Employees table
notesNote - text
etc.

I put both of these tables in a query because I need to make a report with data from both.

My problem: My query will only return results if there is a note in the M_Notes table. I've tried changing it to a LEFT join, RIGHT join, and back to INNER join but I still don't get any employee data (even if they meet the criteria I set) unless there is an associated note in the notes table.

Here is the SQL for my query:

Expand|Select|Wrap|Line Numbers
  1. SELECT M_Employees.empExamMonth, M_Employees.empType, M_Employees.empAgency, M_Employees.empOrg, L_Org.OrgPOC, M_Employees.empSSN, M_Employees.empNameManpower, M_Employees.empPayPlan, M_Employees.empSeries, M_Employees.empPosition, M_Employees.empTOD, M_Employees.empHours, M_Employees.empSupervisor, M_Notes.NoteType, M_Notes.NoteDetail, M_Notes.NoteStatus
  2. FROM (L_Org INNER JOIN M_Employees ON L_Org.OrgID = M_Employees.empOrg) INNER JOIN M_Notes ON M_Employees.empSSN = M_Notes.NoteSSN
  3. WHERE (((M_Employees.empExamMonth) Like [Enter Month]) AND ((M_Employees.empType)=6) AND ((M_Employees.empAgency)=1) AND ((M_Notes.NoteType)=2) AND ((M_Notes.NoteStatus)=Yes)) OR (((M_Employees.empType)=7) AND ((M_Employees.empAgency)=2));
Any idea how to fix this so I get the employee data even if they don't have any notes in the M_Notes table?

Thanks,
Bekah
Nov 25 '09 #1
8 3173
Frinavale
9,735 Recognized Expert Moderator Expert
I could be wrong but I think this problem has to do with your Where statement you have:
Expand|Select|Wrap|Line Numbers
  1. AND ((M_Notes.NoteType)=2) AND ((M_Notes.NoteStatus)=Yes
  2.  
If the NoteStatus is not Yes or NoteType is not 2, then the record won't meet the criteria.

-Frinny
Nov 25 '09 #2
rleepac
22 New Member
Frinny, I could see how you would come to that conclusion but I don't think that's it.

NoteStatus just indicates if it is a current note or not. So NoteStatus = Yes just pulls the current notes.

NoteType just indicates what category the note falls in. So NoteType = 2 means that I only want notes that fall into category 2.

I thought those criteria might be the problem too so I tried running the query without those criteria and I still only got employee records that had a note (of any type or status) attached.

Maybe I need to put criteria in the M_Notes.NoteID like = Null or NotNull?
I don't know the right way to put that in there but I'll play with that option next.
Nov 25 '09 #3
Frinavale
9,735 Recognized Expert Moderator Expert
(Wiki for:SQL Join)

When using an inner join, if there is no matching data to join the records on then these records (that have no match) will not be included in the resulting table.

An outer join does not require each record in the two joined tables to have a matching record....but you said that this doesn't work?

Did you try LEFT OUTTER JOIN?

(see wiki link because I could be wrong about LEFT)

-Frinny
Nov 25 '09 #4
rleepac
22 New Member
Got it! I was entering the criteria wrong. I had it as an AND instead of an OR.

This is the code that got me all the employees that met the criteria regardless of if they had any notes attached. But if they did have any notes they would show up if they met certain criteria.

Whew....thanks for your help!

Expand|Select|Wrap|Line Numbers
  1. SELECT M_Employees.empExamMonth, M_Employees.empType, M_Employees.empAgency, M_Notes.NoteID, M_Employees.empOrg, L_Org.OrgPOC, M_Employees.empSSN, M_Employees.empNameManpower, M_Employees.empPayPlan, M_Employees.empSeries, M_Employees.empPosition, M_Employees.empTOD, M_Employees.empHours, M_Employees.empSupervisor, M_Notes.NoteType, M_Notes.NoteDetail, M_Notes.NoteStatus, M_Notes.NoteDetail
  2. FROM (L_Org INNER JOIN M_Employees ON L_Org.OrgID = M_Employees.empOrg) LEFT JOIN M_Notes ON M_Employees.empSSN = M_Notes.NoteSSN
  3. WHERE (((M_Employees.empExamMonth) Like [Enter Month]) AND ((M_Employees.empType)=6 Or (M_Employees.empType)=9) AND ((M_Employees.empAgency)=1 Or (M_Employees.empAgency)=2) AND ((M_Notes.NoteType)=2 Or (M_Notes.NoteType) Is Null) AND ((M_Notes.NoteStatus)=Yes Or (M_Notes.NoteStatus) Is Null));
Nov 25 '09 #5
topher23
234 Recognized Expert New Member
I was looking over your tables and realized that you might be walking a fine line here. Your tables are using the employee's SSN as an identifier, which is a security no-no, particularly in the state of California, which has the strictest SSN privacy laws in the nation.

The best practice for employee records is to use an AutoNumber field to generate a unique value for each employee, then use that value elsewhere in the database to link to the employee. If the SSN must be in the database, it should be stored once and not referenced by any other table. My preference is actually to store it in a separate table linked to the original employee record with the AutoNumber field, just to maintain a certain level of separation.

Also, any database containing social security numbers needs to be on a secure system, development copies need to be isolated from the network at large (do development on a firewalled computer and don't store development copies on the server), and production databases should be compiled to .mde or .accde.

SSN's are not something to take lightly in this era of identity theft, and if someone gets even a single SSN from your database, your company could be facing major fines and you may even lose your job.
Nov 25 '09 #6
rleepac
22 New Member
Yes, I'm well aware of the problems with using the SSN. I don't have a choice. I'm a contractor providing medical services and the agency I work for files their medical records by SSN. It would literally take a congressional action to change that. However, I do like your idea of storing them in a separate table. I'll have to look at how that will affect the way we access our data. Definitely worth taking a look at. Thanks.

That said, I am on a secured server with development copies isolated, and the production database will be compiled to accde.

Thanks for the info...definite ly don't want to end up in jail or unemployed!
Nov 25 '09 #7
topher23
234 Recognized Expert New Member
I totally understand. I worked as a Patient Administrator in the Army for 8 years - we lived and died by the SSN.

When I had to build a deployable medical tracking system for my regiment, I spent a lot of time and several major rewrites of my system making the SSN accessible to those who needed it, yet at the same time hard to access for someone without a need to know. After a lot of study, I ended up with what I outlined previously.

The nice part is, you can still have forms and reports display all or part of the SSN by using queries, but by not using it directly as an identifier in the tables you restrict access by making it only available to people with permissions to view those forms and reports.
Nov 25 '09 #8
NeoPa
32,567 Recognized Expert Moderator MVP
It seems this was a JOIN problem AND a WHERE criteria problem.

Frinny got both so all good now.
Nov 29 '09 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

13
2726
by: Wescotte | last post by:
Here is a small sample program I wrote in PHP (running off Apache 1.3.31 w/ PHP 5.0.1) to help illustrates problem I'm having. The data base is using DB2 V5R3M0. The client is WinXP machine using the iSeries Client Access Driver ver 10.00.04.00 to connect to the database. The problem is that executing the exact same SQL select statement more than twice int a row stops produces results. The first two instances will always produce the...
3
3044
by: Brian Oster | last post by:
After applying security patch MS03-031 (Sql server ver 8.00.818) a query that used to execute in under 2 seconds, now takes over 8 Minutes to complete. Any ideas on what the heck might be going on? I have tested this extensively and can say for certain that installing this hot fix is what has caused the performance problem. I just don't know why or how to fix it. Brian Oster
1
6171
by: Jeff Blee | last post by:
I hope someone can help me get this graph outputing in proper order. After help from Tom, I got a graph to display output from the previous 12 months and include the average of that output all in the one graph. The output was in the order of the months, but after unioning with the averages SQL code, the order is lost. Below is the full sql code that is the data source for the graph: SELECT (Format(.,"mmm"" '""yy")) AS Month,...
8
6451
by: Adam Louis | last post by:
I would like help resolving this problem. I'm a novice who's been hired to query a hospital database and extract useful information, available to me only in a dynamically generated, downloadable .mdb. The query below query runs correctly and without error, but any attempt to save it causes Access to crash without a message, leaving the .ldb file. Opening the DB reveals it saved a blank "query1". I've upgraded to Jet SP 8, and I'm running...
6
29931
by: Martin Lacoste | last post by:
Ok, before I headbutt the computer... don't know why when I add criteria in a query, I get an 'invalid procedure call'. I also don't know why after searching the help in access, the various access newsgroups, the access support centre, I can seem to find no similar situation. I am not using any references, or VBA at all in the first place. I am trying to set up a simple (or so I thought) query to work with the text of two tables. ...
4
7741
by: Apple | last post by:
1. I want to create an autonumber, my requirement is : 2005/0001 (Year/autonumber), which year & autonumber no. both can auto run. 2. I had create a query by making relation to a table & query, but I can't update record in query or in form. I believe the problem is due to the source query. In source query, there is a filter to show the incomplete record ("is null" in delivery date)], but I need to re-use the job no. if the job is...
11
3137
by: Andy_Khosravi | last post by:
My problem: I'm having trouble with a query taking much too long to run; a query without any criteria evaluating only 650 records takes over 300 seconds to run (over the network. On local drive takes 120 seconds). The Setup: I'm running Access 97 non-developer edition. I have exactly zero other tools to use and no way to change that =(. My database is compiled and resides on a network drive. The database has not been split into a...
4
4293
by: Konrad Hammerer | last post by:
Hi! I have the following problem: I have a query (a) using another query (b) to get the amount of records of this other query (b), means: select count(MNR) as Number from Jahrbuch_Einzelversand_Komplett (while Jahrbuch_Einzelversand_Komplett is a query itself)
4
3124
by: Stan | last post by:
I am using MS Office Access 2003 (11.5614). My basic question is can I run a query of a query datasheet. I want to use more that one criteria and can not get that query to work. I thought I might be able to accomplish the results in two steps by using two queries. If this is possible how can I do it? Thank you, Stan Hanna
2
9833
by: existential.philosophy | last post by:
This is a new problem for me: I have some queries that open very slowly in design view. My benchmark query takes about 20 minutes to open in design view. That same query takes about 20 minutes to open in datasheet view. As an experiment, I deleted all rows in all tables; after that, the query took only seconds to open in both design view and datasheet view. From these facts, I conclude that Access is evaluating the query when I go to...
0
8265
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8196
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8637
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8364
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8504
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7193
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5574
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4092
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2625
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.