I have a problem with using a subquery in MS Access. The purpose of the sub-query is to create a list of people who have had doctor exams in the past 6 months and exclude them from the main query. This is what I came up with: - SELECT GI.generalinfoid AS GeneralInfoId, max(GI.FirstName) AS FirstName, max(GI.LastName) AS LastName, max(TI.ImagingDate) AS ImagingDate, Max(EM.embolizationDate) AS embolizationDate
-
-
FROM tblImaging AS TI RIGHT JOIN (qryGeneralInfo AS GI INNER JOIN tblEmbolizations AS EM ON GI.generalInfoID=EM.peopleID) ON TI.GeneralInfoID=GI.generalinfoid
-
-
WHERE ((GI.name) Is Not Null Or (GI.name)<>"" Or (GI.Lastname) Is Not Null Or (GI.Lastname)<>"") And (GI.generalinfoid)<>14598 And (GI.active) Like "Yes" And (GI.EMBCOUNT)>=1
-
-
-
and TI.GeneralInfoID not in (select distinct GeneralInfoID from tblImaging TI where DateDiff("m",(TI.ImagingDate),Now())<=6)
-
-
-
GROUP BY GI.generalinfoid
-
ORDER BY max(GI.LastName);
The above query does not cause an error but it does not return any data. If I take out the subquery part, it returns over a thousand rows. If I replace "not in" with "in" in the subquery it returns about 65 rows. What can I do to recover the missing 900+ rows with the "not in" subquery?
Incidentally, I tried the following solution but it errored out my Access program: - SELECT GI.generalinfoid AS GeneralInfoId, max(GI.FirstName) AS FirstName, max(GI.LastName) AS LastName, max(TI.ImagingDate) AS ImagingDate, Max(EM.embolizationDate) AS embolizationDate
-
-
-
FROM tblImaging AS TI RIGHT JOIN (qryGeneralInfo AS GI INNER JOIN tblEmbolizations AS EM ON GI.generalInfoID=EM.peopleID) ON TI.GeneralInfoID=GI.generalinfoid
-
-
-
WHERE NOT EXISTS
-
-
(select distinct GeneralInfoID from tblImaging TI where TI.generalInfoID = GI.GeneralInfoID AND DateDiff("m",(TI.ImagingDate),Now())<=6)
-
-
AND
-
-
((GI.name) Is Not Null Or (GI.name)<>"" Or (GI.Lastname) Is Not Null Or (GI.Lastname)<>"") And (GI.active) Like "Yes" And (GI.EMBCOUNT)>=1
-
-
-
GROUP BY GI.generalinfoid
-
ORDER BY max(GI.LastName);
Anyways, any help would be greatly appreciated. Thanks in advance.
13 3833 code green 1,726
Recognized Expert Top Contributor
How many rows does the subquery return? - select distinct GeneralInfoID from tblImaging TI where DateDiff("m",(TI.ImagingDate),Now())<=6
The subquery returns 65 Rows
Rabbit 12,516
Recognized Expert Moderator MVP
Try using a different alias for the subquery. Right now the main query's TI alias overlaps with the subquery's TI, that may be the problem. Or leave off the subquery's alias altogether.
Tried this...Gave me the same result of no rows - SELECT GI.generalinfoid AS GeneralInfoId, max(GI.FirstName) AS FirstName, max(GI.LastName) AS LastName, max(TI.ImagingDate) AS ImagingDate, Max(EM.embolizationDate) AS embolizationDate
-
-
FROM tblImaging AS TI RIGHT JOIN (qryGeneralInfo AS GI INNER JOIN tblEmbolizations AS EM ON GI.generalInfoID=EM.peopleID) ON TI.GeneralInfoID=GI.generalinfoid
-
-
WHERE ((GI.name) Is Not Null Or (GI.name)<>"" Or (GI.Lastname) Is Not Null Or (GI.Lastname)<>"") And (GI.generalinfoid)<>14598 And (GI.active) Like "Yes" And (GI.EMBCOUNT)>=1
-
-
-
and TI.GeneralInfoID not in (select distinct GeneralInfoID from tblImaging tbm where DateDiff("m",(tbm.ImagingDate),Now())<=6)
-
-
-
GROUP BY GI.generalinfoid
-
ORDER BY max(GI.LastName);
NeoPa 32,579
Recognized Expert Moderator MVP
It seems to me that your original line 8 - and TI.GeneralInfoID not in (select distinct GeneralInfoID from tblImaging TI where DateDiff("m",(TI.ImagingDate),Now())<=6)
is equivalent to : - AND DateAdd('m',6,TI.ImagingDate)>=Date()
Would that not be a little more straightforward ?
Rabbit 12,516
Recognized Expert Moderator MVP
It seems to me that your original line 8 - and TI.GeneralInfoID not in (select distinct GeneralInfoID from tblImaging TI where DateDiff("m",(TI.ImagingDate),Now())<=6)
is equivalent to : - AND DateAdd('m',6,TI.ImagingDate)>=Date()
Would that not be a little more straightforward ?
Good catch, totally missed that. I should concern myself more with what the query is trying to achieve.
But a not on aliases. If you use an alias, then every field from that table has to be prefixed with alias.
NeoPa 32,579
Recognized Expert Moderator MVP
But a not on aliases. If you use an alias, then every field from that table has to be prefixed with alias.
Hi PW.
What did you mean by your second paragraph?
Rabbit 12,516
Recognized Expert Moderator MVP
Hi PW.
What did you mean by your second paragraph?
I don't know...
lol, What I meant was:
On a side note. If you use an alias, then every field from that table has to be prefixed with alias.
NeoPa 32,579
Recognized Expert Moderator MVP
A bit like the following? : - SELECT PW.Field1,PW.Field2
-
FROM PeskyWabbit AS PW
Seriously, I didn't find that to be necessarily true in my testing. - SELECT PW.Field1,Field2
-
FROM PeskyWabbit AS PW
worked fine for me (Strangely, I didn't use these exact terms :D).
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Marcin Dobrucki |
last post by:
I've been having some problems with a parse error that I can't figure
out (PHP 4.3.11 on Solaris9). Sample code:
<?php
// getting strange parse errors on this
class A {
var $value;
function A() {
$this->value = 1;
}
|
by: gary |
last post by:
Hi,
We all know the below codes are dangerous:
{
int *p = new int;
delete p;
delete p;
}
And we also know the compilers do not delete p if p==NULL.
So why compilers do not "p = NULL" automatically after programs do "delete p"?
|
by: TCB |
last post by:
Hi,
There are a couple of things that are bothering me, any help on these is
greatly appreciated. This is using ASP.NET 2.0
1. I am sending email in my web app, using a simple form here is the code:
Dim MyMailFrom As New Net.Mail.MailAddress("portal@xxx.com",
"Portal XX.com")
Dim MyMailTo As New Net.Mail.MailAddress("info@xxx.com")
|
by: Chad |
last post by:
Should links automatically appear in the "visited" color as defined by the
user's IE settings without having to add any special coding?
I have a situation where the link was not changing color until I added the
following style:
.vl:visited{color:#808080;}
And then referenced this style in my Anchor:
|
by: Branco Medeiros |
last post by:
Hi all,
Using SQL Server 2000, SP4.
I have a table of street names (Rua) whose ids (cod_rua) are foreign
keys into a consumer table (Consumidor). It turns out that the "Rua"
table has many unused records which I'd like to wipe out. For instance,
there are some 2800 unused records in the "Rua" table, and only some
200 records actually being used by the "Consumidor" table (which,
itself, has some 5000 records).
| |
by: Robbie Hatley |
last post by:
Greetings, group. I just found a weird problem in a program where
a variable declared in a {block} after a "case" keyword was being
treated as having value 0 even though its actual value should
have been something else. An extremely stripped-down version:
int Function (int something)
{
switch(something)
{
case WHATEVER:
|
by: anyonefour |
last post by:
Hai
How we can give the <a href> tag in xml code. Is ther any other tags for giving hyperlink in xml. Please inform me.
Thanks & Regards
|
by: fran7 |
last post by:
Hi, from help in the javascript forum I found the error in some code but need help. This bit of code works perfectly, trouble is I am writing it to a javascript function so the height needs to be in "" instead of "" otherwise I get an error message.
Can anyone suggest how to write it so that it writes " instead of "".
I have tried all combinations of adding " to the code but as soon as I think I am there I get throw out again.
if...
|
by: Muzammil |
last post by:
i have problem with this operator "+" in doubly circular link list.(i
think i have problem with return type).
error is of instantiate error.(mean type dismatch) if any one can help
me please reply.
template <class T>
DoublyCircularLinkList<TDoublyCircularLinkList<T>:: operator +
(const DoublyCircularLinkList& rhs) {
if (head==0 && rhs.head==0) {
|
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,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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...
|
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...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |