Hi
I have a query which calculates the duration of each activity undertaken by a patient by simply deducting the [Start Time] from the [End Time] - I have called this field within the query [Duration]
What I now need is to Total the [Duration] field for the week so I can see the number of hours of activities a patient does in a week
I have used Between Date1 & Date2 in the Date Field Criteria but have no idea what the new formula or expression would be
The query currently returns 3 'records' / lines (as the patient did three activites between the dates selected) but I imagine it has to somehow aggregate these so that each patient only has 1 'record / line
Hope that makes sense (i'm a novice at queries)
5 1151 zmbd 5,501
Recognized Expert Moderator Expert
More information than what you need now; however, you should bookmark for future reference: Sum data by using a query
You'll also want: Aggregate Query Woes
and a handy reference: Basic SQL Syntax for Access Queries
If you are still stuck please post your SQL
Open the Query in design mode
Right click in the table area
Select SQL View
IN a post here, click on the [CODE/] button in the toolbar
Now Cut and Paste the SQL between the two [code][/code] tags.
Thanks again zmbd I'll have a read and see how I get on
I have managed most of what I wanted using a Crosstab Query of a Total Query, both shown below: - SELECT tbl_25_Hours.[Patient ID], tbl_25_Hours.[Activity Date], tbl_25_Hours.[Start Time], tbl_25_Hours.[End Time], tbl_25_Hours.Activity, tbl_Patient_Information.Surname, tbl_Patient_Information.[Forename(s)], Sum([End Time]-[Start Time]) AS Duration
-
FROM tbl_Patient_Information INNER JOIN (tbl_Admissions INNER JOIN tbl_25_Hours ON tbl_Admissions.[Patient ID] = tbl_25_Hours.[Patient ID]) ON tbl_Patient_Information.[NHS Number] = tbl_Admissions.[NHS Number]
-
GROUP BY tbl_25_Hours.[Patient ID], tbl_25_Hours.[Activity Date], tbl_25_Hours.[Start Time], tbl_25_Hours.[End Time], tbl_25_Hours.Activity, tbl_Patient_Information.Surname, tbl_Patient_Information.[Forename(s)]
-
HAVING (((tbl_25_Hours.[Activity Date]) Between #6/10/2014# And #6/17/2014#));
- TRANSFORM Sum([25 Hour Activity Duration Calculation].Duration) AS SumOfDuration
-
SELECT [25 Hour Activity Duration Calculation].[Patient ID], Sum([25 Hour Activity Duration Calculation].Duration) AS [Total Of Duration]
-
FROM [25 Hour Activity Duration Calculation]
-
GROUP BY [25 Hour Activity Duration Calculation].[Patient ID]
-
PIVOT [25 Hour Activity Duration Calculation].Activity;
-
What I'd like is for the date part (bold) to be input by the user
I tried to make the Total Query a Parameter query using [Activity Date] BUT got the following message: "This expression is typed incorrectly, or it is too complex to be evaluated. For example, a numeric expression may contain too many complicated elements. Try simplifying the expression by assigning parts of the expression to variables"
Any advice?
twinnyfo 3,653
Recognized Expert Moderator Specialist
Hargo,
Concerning your first question, change line 4 of your first block of code to: - HAVING (((tbl_25_Hours.[Activity Date]) Between [Start Date?] And [Stop Date?]));
You just have to make sure that the user enters a valid date format (e.g. m/d/yy). You can put that into your input string, too. - HAVING (((tbl_25_Hours.[Activity Date]) Between [Start Date (m/d/yy)?] And [Stop Date (m/d/yy)?]));
This can become challenging if this is a raw SQL query. If you were building your string in VBA, you could validate a date.
Hope this hepps!
Hi Twinnyfo
Just checking through the workings of Db and a problem has popped up with this crosstab query
Since Patient ID became a lookup of AdmisisonsKey I am getting: Type mismatch in expression message when I try to run the query
It appears to NOT like PatientID as a row heading, presumably because it is a number now rather than text?
Any suggestions on a fix?
Here's the code - PARAMETERS [Start Date] DateTime, [End Date] DateTime;
-
TRANSFORM Sum([qry_Activity_Duration_&_Dates_Select].Duration) AS SumOfDuration
-
SELECT [qry_Activity_Duration_&_Dates_Select].PatientID, [qry_Activity_Duration_&_Dates_Select].Forenames, [qry_Activity_Duration_&_Dates_Select].Surname, Sum([qry_Activity_Duration_&_Dates_Select].Duration) AS TotalActivityDuration
-
FROM [qry_Activity_Duration_&_Dates_Select]
-
WHERE ((([qry_Activity_Duration_&_Dates_Select].ActivityDate)>=[Start Date] And ([qry_Activity_Duration_&_Dates_Select].ActivityDate)<=[End Date]) AND (([qry_Activity_Duration_&_Dates_Select].Outcome)="Accepted"))
-
GROUP BY [qry_Activity_Duration_&_Dates_Select].PatientID, [qry_Activity_Duration_&_Dates_Select].Forenames, [qry_Activity_Duration_&_Dates_Select].Surname
-
PIVOT [qry_Activity_Duration_&_Dates_Select].Activity;
-
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Manfred |
last post by:
Hi
Would like to add a new Field to Table which is 75 % (or another
Percentage) higher than the Value in another Field in same Table.Is
this possible with Expression or would I have to enter the...
|
by: Richard Holliingsworth |
last post by:
Hello:
Thanks for reading this post.
I need to create a metrics (form or report - I don't care which) to
display calculated fields about the database (A2002 front end to SQL
Server 2K)
1) I...
|
by: hhathome |
last post by:
In my report I have a calculated DateDiff Field, I also have a
calculated count field. I'm trying to get a total of the DateDiff
field and dividing it by the count field and I'm having problems --...
|
by: John |
last post by:
I am using Access 2000.
One table in my database has a field called RankName.
Values inlcude: Officer, Sergeant, Lieutenant.
I need create a report that groups these three RankNames into two...
|
by: ey.markov |
last post by:
Greetings,
in A2K VBA, I set the following recordset:
Set rsGPValue = dbs.OpenRecordset("SELECT *,
DateSerial(Year(),Month()+4,0) FROM tblGPValue AS
OurDate, dbOpenSnapshot)
and then I try...
| |
by: Henrik |
last post by:
The problem is (using MS Access 2003) I am unable to retrieve long
strings (255 chars) from calculated fields through a recordset.
The data takes the trip in three phases:
1. A custom public...
|
by: Haas C |
last post by:
Hi all!
Is there anyway I can override a value in a calculated field on a
form? For example:
I have a form which displays the following fields based on a query:
Premium Due field has the...
|
by: fperri |
last post by:
Hello,
I have a calculated field in my query that uses a function to come up with the value. The function has various fields from the table used in the query passed into it as parameters. For some...
|
by: myemail.an |
last post by:
I use Access 2007 and create queries with a number of calculated
fields/expressions (I'm still a novice so please forgive me if my
wording is imprecise...), like: MyCalculation = Field1 - Field2.
...
|
by: mkbrady |
last post by:
I have a query that includes calculated fields that generate numeric results.
I have wrapped conversion functions CLng() and CDdl() around the calculated
fields to ensure the data types are...
|
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...
| |
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,...
|
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...
|
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...
|
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,...
|
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...
|
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...
| |
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |