No records with date criteria

L

Linda \(RQ\)

Hi Everyone,

Using Access 2003. I have a query, sql below but I use the query grid to
make my queries. When I put in a criteria [Enter Date] under my date field
so I can see the patients started on therapy yesterday, I get no records.
The field is a Date/Time field with data and time in it. I thought maybe I
needed to get the time out of the way so, I clicked on the field and changed
the properties to "short date" That worked as far as only showing the date
but still if I put the [Enter Date] in the criteria, there are no records
showing when I type in a date (I am sure I am typing in a date that there
are records for). If I take the criteria out, I can see all the records.

SELECT tblPatients.PtID, tblPtThpy.PtThpyID, tblTherapyType.TherapyTypeID,
tblPtThpy.ThpyEndDtTm, tblPtThpy.ThpyStDtTm
FROM tblPatients INNER JOIN (tblTherapyType INNER JOIN tblPtThpy ON
tblTherapyType.TherapyTypeID = tblPtThpy.ThpyTypeID_fk) ON tblPatients.PtID
= tblPtThpy.PtID_fk
GROUP BY tblPatients.PtID, tblPtThpy.PtThpyID, tblTherapyType.TherapyTypeID,
tblPtThpy.ThpyEndDtTm, tblPtThpy.ThpyStDtTm
HAVING (((tblTherapyType.TherapyTypeID)=41 Or
(tblTherapyType.TherapyTypeID)=55 Or (tblTherapyType.TherapyTypeID)=57) AND
((tblPtThpy.ThpyEndDtTm) Is Null));


Thanks,
Linda
 
A

Allen Browne

Your analysis is right: the problem is the time value in the date/time
field.
But just setting the Format property to suppress the time part doesn't solve
it, as you found.

Instead, as for all the records between this date and the next. Something
like this:

PARAMETERS [Enter Date] DateTime;
SELECT tblPatients.PtID, tblPtThpy.PtThpyID,
tblTherapyType.TherapyTypeID, tblPtThpy.ThpyEndDtTm,
tblPtThpy.ThpyStDtTm
FROM tblPatients INNER JOIN (tblTherapyType INNER JOIN tblPtThpy
ON tblTherapyType.TherapyTypeID = tblPtThpy.ThpyTypeID_fk)
ON tblPatients.PtID = tblPtThpy.PtID_fk
WHERE ((tblPtThpy.ThpyEndDtTm >= [Enter Date])
AND (tblPtThpy.ThpyEndDtTm < [Enter Date] + 1)
AND ((tblTherapyType.TherapyTypeID IN (41, 55, 57))
OR (tblTherapyType.TherapyTypeID Is Null)))
GROUP BY tblPatients.PtID, tblPtThpy.PtThpyID,
tblTherapyType.TherapyTypeID,tblPtThpy.ThpyEndDtTm,
tblPtThpy.ThpyStDtTm;

The main change is the WHERE clause asking for dates greater than or equal
to the parameter, but less than the next day - that's all times on that
date.

In the interests of efficiency, I moved the other criteria into the WHERE
clause as well (rather than the HAVING clause which is applied after
aggregation), and used the IN operator instead of many ORs.

Oh, and declaring the parameter helps ensure the query gets it right as
well, particularly if you use a non-US date format. More about that here:
http://allenbrowne.com/ser-36.html

It's untested, so may need some fixing up (e.g. if the brackets are
mismatched.)

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Linda (RQ) said:
Hi Everyone,

Using Access 2003. I have a query, sql below but I use the query grid to
make my queries. When I put in a criteria [Enter Date] under my date
field
so I can see the patients started on therapy yesterday, I get no records.
The field is a Date/Time field with data and time in it. I thought maybe
I
needed to get the time out of the way so, I clicked on the field and
changed
the properties to "short date" That worked as far as only showing the
date
but still if I put the [Enter Date] in the criteria, there are no records
showing when I type in a date (I am sure I am typing in a date that there
are records for). If I take the criteria out, I can see all the records.

SELECT tblPatients.PtID, tblPtThpy.PtThpyID, tblTherapyType.TherapyTypeID,
tblPtThpy.ThpyEndDtTm, tblPtThpy.ThpyStDtTm
FROM tblPatients INNER JOIN (tblTherapyType INNER JOIN tblPtThpy ON
tblTherapyType.TherapyTypeID = tblPtThpy.ThpyTypeID_fk) ON
tblPatients.PtID
= tblPtThpy.PtID_fk
GROUP BY tblPatients.PtID, tblPtThpy.PtThpyID,
tblTherapyType.TherapyTypeID,
tblPtThpy.ThpyEndDtTm, tblPtThpy.ThpyStDtTm
HAVING (((tblTherapyType.TherapyTypeID)=41 Or
(tblTherapyType.TherapyTypeID)=55 Or (tblTherapyType.TherapyTypeID)=57)
AND
((tblPtThpy.ThpyEndDtTm) Is Null));


Thanks,
Linda
 
G

Guest

You should not use parameter prompt queries. It is much better to use
criteria entered into controls on forms.

SELECT tblPatients.PtID, tblPtThpy.PtThpyID, tblTherapyType.TherapyTypeID,
tblPtThpy.ThpyEndDtTm, tblPtThpy.ThpyStDtTm
FROM tblPatients INNER JOIN (tblTherapyType INNER JOIN tblPtThpy ON
tblTherapyType.TherapyTypeID = tblPtThpy.ThpyTypeID_fk) ON tblPatients.PtID
= tblPtThpy.PtID_fk
WHERE DateValue(ThpyStDatTm) = Forms!frmDateCriteria!txtStartDate
GROUP BY tblPatients.PtID, tblPtThpy.PtThpyID, tblTherapyType.TherapyTypeID,
tblPtThpy.ThpyEndDtTm, tblPtThpy.ThpyStDtTm
HAVING (((tblTherapyType.TherapyTypeID)=41 Or
(tblTherapyType.TherapyTypeID)=55 Or (tblTherapyType.TherapyTypeID)=57) AND
((tblPtThpy.ThpyEndDtTm) Is Null));
 
L

Linda \(RQ\)

Thanks, Allen. I'll check this all out tomorrow. Can I use the query grid
for this? I am starting to get the idea on what's going on when I see some
simple sql but I need to use the grid to actually "get it".

Linda


Allen Browne said:
Your analysis is right: the problem is the time value in the date/time
field.
But just setting the Format property to suppress the time part doesn't
solve it, as you found.

Instead, as for all the records between this date and the next. Something
like this:

PARAMETERS [Enter Date] DateTime;
SELECT tblPatients.PtID, tblPtThpy.PtThpyID,
tblTherapyType.TherapyTypeID, tblPtThpy.ThpyEndDtTm,
tblPtThpy.ThpyStDtTm
FROM tblPatients INNER JOIN (tblTherapyType INNER JOIN tblPtThpy
ON tblTherapyType.TherapyTypeID = tblPtThpy.ThpyTypeID_fk)
ON tblPatients.PtID = tblPtThpy.PtID_fk
WHERE ((tblPtThpy.ThpyEndDtTm >= [Enter Date])
AND (tblPtThpy.ThpyEndDtTm < [Enter Date] + 1)
AND ((tblTherapyType.TherapyTypeID IN (41, 55, 57))
OR (tblTherapyType.TherapyTypeID Is Null)))
GROUP BY tblPatients.PtID, tblPtThpy.PtThpyID,
tblTherapyType.TherapyTypeID,tblPtThpy.ThpyEndDtTm,
tblPtThpy.ThpyStDtTm;

The main change is the WHERE clause asking for dates greater than or equal
to the parameter, but less than the next day - that's all times on that
date.

In the interests of efficiency, I moved the other criteria into the WHERE
clause as well (rather than the HAVING clause which is applied after
aggregation), and used the IN operator instead of many ORs.

Oh, and declaring the parameter helps ensure the query gets it right as
well, particularly if you use a non-US date format. More about that here:
http://allenbrowne.com/ser-36.html

It's untested, so may need some fixing up (e.g. if the brackets are
mismatched.)

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Linda (RQ) said:
Hi Everyone,

Using Access 2003. I have a query, sql below but I use the query grid to
make my queries. When I put in a criteria [Enter Date] under my date
field
so I can see the patients started on therapy yesterday, I get no records.
The field is a Date/Time field with data and time in it. I thought maybe
I
needed to get the time out of the way so, I clicked on the field and
changed
the properties to "short date" That worked as far as only showing the
date
but still if I put the [Enter Date] in the criteria, there are no records
showing when I type in a date (I am sure I am typing in a date that there
are records for). If I take the criteria out, I can see all the records.

SELECT tblPatients.PtID, tblPtThpy.PtThpyID,
tblTherapyType.TherapyTypeID,
tblPtThpy.ThpyEndDtTm, tblPtThpy.ThpyStDtTm
FROM tblPatients INNER JOIN (tblTherapyType INNER JOIN tblPtThpy ON
tblTherapyType.TherapyTypeID = tblPtThpy.ThpyTypeID_fk) ON
tblPatients.PtID
= tblPtThpy.PtID_fk
GROUP BY tblPatients.PtID, tblPtThpy.PtThpyID,
tblTherapyType.TherapyTypeID,
tblPtThpy.ThpyEndDtTm, tblPtThpy.ThpyStDtTm
HAVING (((tblTherapyType.TherapyTypeID)=41 Or
(tblTherapyType.TherapyTypeID)=55 Or (tblTherapyType.TherapyTypeID)=57)
AND
((tblPtThpy.ThpyEndDtTm) Is Null));


Thanks,
Linda
 
L

Linda \(RQ\)

Umm........That sounds hard. In the old database the query thing worked
well (but that database was flat and the records were deleted once the
patient was discharged), this is just a list of names for a person to print
out to go round on the patients who were started on therapy just the day
before.

I am really tired, and will look up more tomorrow, but found this quickly,
it this site what you are talking about? It seems like "code" is necessary
and I haven't had much luck with code so far.
http://www.ukaug.co.uk/TPQBF.asp

Thanks,
Linda

Duane Hookom said:
You should not use parameter prompt queries. It is much better to use
criteria entered into controls on forms.

SELECT tblPatients.PtID, tblPtThpy.PtThpyID, tblTherapyType.TherapyTypeID,
tblPtThpy.ThpyEndDtTm, tblPtThpy.ThpyStDtTm
FROM tblPatients INNER JOIN (tblTherapyType INNER JOIN tblPtThpy ON
tblTherapyType.TherapyTypeID = tblPtThpy.ThpyTypeID_fk) ON
tblPatients.PtID
= tblPtThpy.PtID_fk
WHERE DateValue(ThpyStDatTm) = Forms!frmDateCriteria!txtStartDate
GROUP BY tblPatients.PtID, tblPtThpy.PtThpyID,
tblTherapyType.TherapyTypeID,
tblPtThpy.ThpyEndDtTm, tblPtThpy.ThpyStDtTm
HAVING (((tblTherapyType.TherapyTypeID)=41 Or
(tblTherapyType.TherapyTypeID)=55 Or (tblTherapyType.TherapyTypeID)=57)
AND
((tblPtThpy.ThpyEndDtTm) Is Null));

--
Duane Hookom
Microsoft Access MVP


Linda (RQ) said:
Hi Everyone,

Using Access 2003. I have a query, sql below but I use the query grid to
make my queries. When I put in a criteria [Enter Date] under my date
field
so I can see the patients started on therapy yesterday, I get no records.
The field is a Date/Time field with data and time in it. I thought maybe
I
needed to get the time out of the way so, I clicked on the field and
changed
the properties to "short date" That worked as far as only showing the
date
but still if I put the [Enter Date] in the criteria, there are no records
showing when I type in a date (I am sure I am typing in a date that there
are records for). If I take the criteria out, I can see all the records.

SELECT tblPatients.PtID, tblPtThpy.PtThpyID,
tblTherapyType.TherapyTypeID,
tblPtThpy.ThpyEndDtTm, tblPtThpy.ThpyStDtTm
FROM tblPatients INNER JOIN (tblTherapyType INNER JOIN tblPtThpy ON
tblTherapyType.TherapyTypeID = tblPtThpy.ThpyTypeID_fk) ON
tblPatients.PtID
= tblPtThpy.PtID_fk
GROUP BY tblPatients.PtID, tblPtThpy.PtThpyID,
tblTherapyType.TherapyTypeID,
tblPtThpy.ThpyEndDtTm, tblPtThpy.ThpyStDtTm
HAVING (((tblTherapyType.TherapyTypeID)=41 Or
(tblTherapyType.TherapyTypeID)=55 Or (tblTherapyType.TherapyTypeID)=57)
AND
((tblPtThpy.ThpyEndDtTm) Is Null));


Thanks,
Linda
 
A

Allen Browne

You can use the query design grid.

To enter the parameter, choose Parameters on the Query menu.
In the dialog, enter:
[Enter Date] Date

In the Criteria row under TherapyTypeID, type:
Is Null OR IN (41,55,57)

In the Criteria row under ThpyEndDtTm, enter:
= [Enter Date] OR < [Enter Date] + 1

Duane's suggestion of using DateValue() will work too. My preference for the
"less than the next day" approach is that it can use any index you have on
the date field.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Linda (RQ) said:
Thanks, Allen. I'll check this all out tomorrow. Can I use the query
grid for this? I am starting to get the idea on what's going on when I
see some simple sql but I need to use the grid to actually "get it".

Linda


Allen Browne said:
Your analysis is right: the problem is the time value in the date/time
field.
But just setting the Format property to suppress the time part doesn't
solve it, as you found.

Instead, as for all the records between this date and the next. Something
like this:

PARAMETERS [Enter Date] DateTime;
SELECT tblPatients.PtID, tblPtThpy.PtThpyID,
tblTherapyType.TherapyTypeID, tblPtThpy.ThpyEndDtTm,
tblPtThpy.ThpyStDtTm
FROM tblPatients INNER JOIN (tblTherapyType INNER JOIN tblPtThpy
ON tblTherapyType.TherapyTypeID = tblPtThpy.ThpyTypeID_fk)
ON tblPatients.PtID = tblPtThpy.PtID_fk
WHERE ((tblPtThpy.ThpyEndDtTm >= [Enter Date])
AND (tblPtThpy.ThpyEndDtTm < [Enter Date] + 1)
AND ((tblTherapyType.TherapyTypeID IN (41, 55, 57))
OR (tblTherapyType.TherapyTypeID Is Null)))
GROUP BY tblPatients.PtID, tblPtThpy.PtThpyID,
tblTherapyType.TherapyTypeID,tblPtThpy.ThpyEndDtTm,
tblPtThpy.ThpyStDtTm;

The main change is the WHERE clause asking for dates greater than or
equal to the parameter, but less than the next day - that's all times on
that date.

In the interests of efficiency, I moved the other criteria into the WHERE
clause as well (rather than the HAVING clause which is applied after
aggregation), and used the IN operator instead of many ORs.

Oh, and declaring the parameter helps ensure the query gets it right as
well, particularly if you use a non-US date format. More about that here:
http://allenbrowne.com/ser-36.html

It's untested, so may need some fixing up (e.g. if the brackets are
mismatched.)

Linda (RQ) said:
Hi Everyone,

Using Access 2003. I have a query, sql below but I use the query grid
to
make my queries. When I put in a criteria [Enter Date] under my date
field
so I can see the patients started on therapy yesterday, I get no
records.
The field is a Date/Time field with data and time in it. I thought
maybe I
needed to get the time out of the way so, I clicked on the field and
changed
the properties to "short date" That worked as far as only showing the
date
but still if I put the [Enter Date] in the criteria, there are no
records
showing when I type in a date (I am sure I am typing in a date that
there
are records for). If I take the criteria out, I can see all the
records.

SELECT tblPatients.PtID, tblPtThpy.PtThpyID,
tblTherapyType.TherapyTypeID,
tblPtThpy.ThpyEndDtTm, tblPtThpy.ThpyStDtTm
FROM tblPatients INNER JOIN (tblTherapyType INNER JOIN tblPtThpy ON
tblTherapyType.TherapyTypeID = tblPtThpy.ThpyTypeID_fk) ON
tblPatients.PtID
= tblPtThpy.PtID_fk
GROUP BY tblPatients.PtID, tblPtThpy.PtThpyID,
tblTherapyType.TherapyTypeID,
tblPtThpy.ThpyEndDtTm, tblPtThpy.ThpyStDtTm
HAVING (((tblTherapyType.TherapyTypeID)=41 Or
(tblTherapyType.TherapyTypeID)=55 Or (tblTherapyType.TherapyTypeID)=57)
AND
((tblPtThpy.ThpyEndDtTm) Is Null));
 
A

Allen Browne

Oops: The criteria for the date should be an AND:
= [Enter Date] AND < [Enter Date] + 1

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Allen Browne said:
You can use the query design grid.

To enter the parameter, choose Parameters on the Query menu.
In the dialog, enter:
[Enter Date] Date

In the Criteria row under TherapyTypeID, type:
Is Null OR IN (41,55,57)

In the Criteria row under ThpyEndDtTm, enter:
= [Enter Date] OR < [Enter Date] + 1

Duane's suggestion of using DateValue() will work too. My preference for
the "less than the next day" approach is that it can use any index you
have on the date field.

Linda (RQ) said:
Thanks, Allen. I'll check this all out tomorrow. Can I use the query
grid for this? I am starting to get the idea on what's going on when I
see some simple sql but I need to use the grid to actually "get it".

Linda


Allen Browne said:
Your analysis is right: the problem is the time value in the date/time
field.
But just setting the Format property to suppress the time part doesn't
solve it, as you found.

Instead, as for all the records between this date and the next.
Something like this:

PARAMETERS [Enter Date] DateTime;
SELECT tblPatients.PtID, tblPtThpy.PtThpyID,
tblTherapyType.TherapyTypeID, tblPtThpy.ThpyEndDtTm,
tblPtThpy.ThpyStDtTm
FROM tblPatients INNER JOIN (tblTherapyType INNER JOIN tblPtThpy
ON tblTherapyType.TherapyTypeID = tblPtThpy.ThpyTypeID_fk)
ON tblPatients.PtID = tblPtThpy.PtID_fk
WHERE ((tblPtThpy.ThpyEndDtTm >= [Enter Date])
AND (tblPtThpy.ThpyEndDtTm < [Enter Date] + 1)
AND ((tblTherapyType.TherapyTypeID IN (41, 55, 57))
OR (tblTherapyType.TherapyTypeID Is Null)))
GROUP BY tblPatients.PtID, tblPtThpy.PtThpyID,
tblTherapyType.TherapyTypeID,tblPtThpy.ThpyEndDtTm,
tblPtThpy.ThpyStDtTm;

The main change is the WHERE clause asking for dates greater than or
equal to the parameter, but less than the next day - that's all times on
that date.

In the interests of efficiency, I moved the other criteria into the
WHERE clause as well (rather than the HAVING clause which is applied
after aggregation), and used the IN operator instead of many ORs.

Oh, and declaring the parameter helps ensure the query gets it right as
well, particularly if you use a non-US date format. More about that
here:
http://allenbrowne.com/ser-36.html

It's untested, so may need some fixing up (e.g. if the brackets are
mismatched.)

Hi Everyone,

Using Access 2003. I have a query, sql below but I use the query grid
to
make my queries. When I put in a criteria [Enter Date] under my date
field
so I can see the patients started on therapy yesterday, I get no
records.
The field is a Date/Time field with data and time in it. I thought
maybe I
needed to get the time out of the way so, I clicked on the field and
changed
the properties to "short date" That worked as far as only showing the
date
but still if I put the [Enter Date] in the criteria, there are no
records
showing when I type in a date (I am sure I am typing in a date that
there
are records for). If I take the criteria out, I can see all the
records.

SELECT tblPatients.PtID, tblPtThpy.PtThpyID,
tblTherapyType.TherapyTypeID,
tblPtThpy.ThpyEndDtTm, tblPtThpy.ThpyStDtTm
FROM tblPatients INNER JOIN (tblTherapyType INNER JOIN tblPtThpy ON
tblTherapyType.TherapyTypeID = tblPtThpy.ThpyTypeID_fk) ON
tblPatients.PtID
= tblPtThpy.PtID_fk
GROUP BY tblPatients.PtID, tblPtThpy.PtThpyID,
tblTherapyType.TherapyTypeID,
tblPtThpy.ThpyEndDtTm, tblPtThpy.ThpyStDtTm
HAVING (((tblTherapyType.TherapyTypeID)=41 Or
(tblTherapyType.TherapyTypeID)=55 Or (tblTherapyType.TherapyTypeID)=57)
AND
((tblPtThpy.ThpyEndDtTm) Is Null));
 
G

Guest

IMHO entering values at parameter prompts isn't appropriate in Access apps.
If you want to use them, then consider using Allen's quality reply.

--
Duane Hookom
Microsoft Access MVP


Linda (RQ) said:
Umm........That sounds hard. In the old database the query thing worked
well (but that database was flat and the records were deleted once the
patient was discharged), this is just a list of names for a person to print
out to go round on the patients who were started on therapy just the day
before.

I am really tired, and will look up more tomorrow, but found this quickly,
it this site what you are talking about? It seems like "code" is necessary
and I haven't had much luck with code so far.
http://www.ukaug.co.uk/TPQBF.asp

Thanks,
Linda

Duane Hookom said:
You should not use parameter prompt queries. It is much better to use
criteria entered into controls on forms.

SELECT tblPatients.PtID, tblPtThpy.PtThpyID, tblTherapyType.TherapyTypeID,
tblPtThpy.ThpyEndDtTm, tblPtThpy.ThpyStDtTm
FROM tblPatients INNER JOIN (tblTherapyType INNER JOIN tblPtThpy ON
tblTherapyType.TherapyTypeID = tblPtThpy.ThpyTypeID_fk) ON
tblPatients.PtID
= tblPtThpy.PtID_fk
WHERE DateValue(ThpyStDatTm) = Forms!frmDateCriteria!txtStartDate
GROUP BY tblPatients.PtID, tblPtThpy.PtThpyID,
tblTherapyType.TherapyTypeID,
tblPtThpy.ThpyEndDtTm, tblPtThpy.ThpyStDtTm
HAVING (((tblTherapyType.TherapyTypeID)=41 Or
(tblTherapyType.TherapyTypeID)=55 Or (tblTherapyType.TherapyTypeID)=57)
AND
((tblPtThpy.ThpyEndDtTm) Is Null));

--
Duane Hookom
Microsoft Access MVP


Linda (RQ) said:
Hi Everyone,

Using Access 2003. I have a query, sql below but I use the query grid to
make my queries. When I put in a criteria [Enter Date] under my date
field
so I can see the patients started on therapy yesterday, I get no records.
The field is a Date/Time field with data and time in it. I thought maybe
I
needed to get the time out of the way so, I clicked on the field and
changed
the properties to "short date" That worked as far as only showing the
date
but still if I put the [Enter Date] in the criteria, there are no records
showing when I type in a date (I am sure I am typing in a date that there
are records for). If I take the criteria out, I can see all the records.

SELECT tblPatients.PtID, tblPtThpy.PtThpyID,
tblTherapyType.TherapyTypeID,
tblPtThpy.ThpyEndDtTm, tblPtThpy.ThpyStDtTm
FROM tblPatients INNER JOIN (tblTherapyType INNER JOIN tblPtThpy ON
tblTherapyType.TherapyTypeID = tblPtThpy.ThpyTypeID_fk) ON
tblPatients.PtID
= tblPtThpy.PtID_fk
GROUP BY tblPatients.PtID, tblPtThpy.PtThpyID,
tblTherapyType.TherapyTypeID,
tblPtThpy.ThpyEndDtTm, tblPtThpy.ThpyStDtTm
HAVING (((tblTherapyType.TherapyTypeID)=41 Or
(tblTherapyType.TherapyTypeID)=55 Or (tblTherapyType.TherapyTypeID)=57)
AND
((tblPtThpy.ThpyEndDtTm) Is Null));


Thanks,
Linda
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top