473,324 Members | 2,214 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Finding the maximum value across several fields in a query

Hi,

I have a query that looks like this:

PatientID LastVisit LastMed LastVaccine
1001 1/1/2004 3/1/2004 10/1/2004
1002 10/1/2005 3/1/2004 10/1/2004
.....

I need a calculated field (let's call it LastActivity) that contains
the maximum of LastVisit, LastMed, and LastVaccine. Thus, lastActivity
should be 10/1/2004 for the first record and 10/1/2005 for the second
record in the example above. Any ideas?

Thanks,

Nov 13 '05 #1
4 2659

benignor wrote:
Hi,

I have a query that looks like this:

PatientID LastVisit LastMed LastVaccine
1001 1/1/2004 3/1/2004 10/1/2004
1002 10/1/2005 3/1/2004 10/1/2004
....

I need a calculated field (let's call it LastActivity) that contains
the maximum of LastVisit, LastMed, and LastVaccine. Thus, lastActivity
should be 10/1/2004 for the first record and 10/1/2005 for the second
record in the example above. Any ideas?

Thanks,


http://groups.google.com/group/comp....211fb18?hl=en&

should give you some ideas. I should think about the problem to see if
there's a better way, but I don't feel like doing any thinking today.
Sorry.

James A. Fortune

Nov 13 '05 #2

benignor wrote:
Hi,

I have a query that looks like this:

PatientID LastVisit LastMed LastVaccine
1001 1/1/2004 3/1/2004 10/1/2004
1002 10/1/2005 3/1/2004 10/1/2004
....

I need a calculated field (let's call it LastActivity) that contains
the maximum of LastVisit, LastMed, and LastVaccine. Thus, lastActivity
should be 10/1/2004 for the first record and 10/1/2005 for the second
record in the example above. Any ideas?

Thanks,


If you only need the date, then just create a union query of the 3
"visits".

SELECT PatientID, LastVisit AS SomeDate
UNION ALL
SELECT PatientID, LastMed AS SomeDate
UNION ALL
SELECT PatientID, LastVaccine AS SomeDate;

Then you can do a summary query on that and get the MAX of the dates.

Nov 13 '05 #3
LOL... you forgot to hang the "temporarily out of service" sign on your
head.

Nov 13 '05 #4
pi********@hotmail.com wrote:
LOL... you forgot to hang the "temporarily out of service" sign on your
head.


Catch 22. The "temporarily out of service" sign that I forgot covers
forgetting it :-).

James A. Fortune

Nov 13 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Shufen | last post by:
Hi, I'm a newbie that just started to learn python, html and etc. I have some questions to ask and hope that someone can help me on. I'm trying to code a python script (with HTML) to get...
20
by: | last post by:
If I need to check if a certain value does exist in a field, and return either "yes" or "not" which query would be the most effestive?
2
by: rivka.howley | last post by:
I wrote some code that creates a table with a date/time field at 15-minute intervals. Here's how I create and populate the table With tblDataTemp ..Fields.Append .CreateField("CT_ID", dbLong)...
11
by: ian.davies52 | last post by:
Is there anything I can do about the apparent limit on the number of textboxes that have calculations as their control source on a form or report in ms-access? I have a query that pulls together...
1
by: Net Virtual Mailing Lists | last post by:
Hello, Lets say I have data like this: value1|value2|value3|value4|....|value(N) ------|------|------|------|----|-------- 100 | 200 | 300 | 400 | | 10 | 20 | | 40 | ...
2
by: ElkGroveR | last post by:
Hi there! I'm using PHP to create a simple, dynamic MySQL SELECT query. The user chooses a selection from a HTML Form SELECT element's many options and submits the form via a POST action. ...
4
by: kenny | last post by:
hi everybody, i have a question which may be rather trivial to some of you: in my scenario i have three columns with col 1 and 2 holding integers and i want to know the respective maximum for...
13
by: Shutey | last post by:
I have a strange issue with dropdowns. Using php4, mySQL5, Apache 2 on a fast XP pro PC, I have a form which requires 5 dropdowns populated with indentical values. I extract the values using SQL...
4
by: SjaakBanaan | last post by:
Hey all, I have a question that ought to be simple but has given me headaches for a while. I have a table with contact email addresses, say. T ID ContID Priority Emailaddress...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.