473,940 Members | 5,324 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2734

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 "temporaril y out of service" sign on your
head.

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


Catch 22. The "temporaril y 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
6181
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 values from a html form that consists of about 10 checkbox and a textbox where user have to key in a value to perform a search. From python tutors, I learned that I have to use the following method:
20
10194
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
3182
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) ..Fields.Append .CreateField(strTmpIDFld, dbLong) ..Fields.Append .CreateField(strTmpDateFld, dbDate) ..Fields.Append .CreateField(strTmpDataFld, dbDouble)
11
3180
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 all the fields from two tables, each with about 20 fields. I then have a statistics form that has the query as its source and the form has 273 textboxes on, each with a calculation based on the underlying query values. The form looks like a...
1
3379
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 | | | 15 | | 16 | |
2
2865
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. The SELECT query is built as follows: $itemtype = stripslashes(trim($_POST));
4
6395
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 each row in col 3. i´ve been using something with max(...) but it works only for 1 parameter. i want to use only sql, no further vb... would be great if someone could help.... thx!
13
2212
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 and populate 2 variables and use a for-next loop to create the dropdown. The dropdown contains some 310 items! It works beautifully if I have 1 or 2 dropdowns but as soon as I add more it partially creates the 3rd and just stops until it times out!...
4
3968
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
11525
Oralloy
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...
1
11293
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
10659
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
9858
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
7389
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
6077
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...
0
6297
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4908
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
3
3502
bsmnconsultancy
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...

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.