Solved

Finding the max entered in the fields

Posted on 2007-11-26
8
160 Views
Last Modified: 2010-04-06
Ok, I have 6 numeric textfields. I want to display the max of the 6 fields. How can I do this? The only appraoch I had in mind is with a list, but I know there's another way. maybe a quesry loop on the 6 fields to find the max? HELP
0
Comment
Question by:FIATECH
  • 4
  • 4
8 Comments
 
LVL 52

Expert Comment

by:_agx_
ID: 20352411
Can you give an example of what you mean with the desired results?
0
 

Author Comment

by:FIATECH
ID: 20352434
yes. <cfoutput>#biggestnumber#</cfoutput>

if 10, 89, 35, 3, 5, 78 was entered I just want to get the saved result in the DB to display. SO maybe I can pull those variables from the DB and just show the max? Its sounds so easy but I can't do it!
0
 
LVL 52

Expert Comment

by:_agx_
ID: 20352453
If they values are entered into a column named "ColumnA" you could just use MAX

<cfquery name="yourQuery" ...>
SELECT MAX(ColumnA) AS biggestnumber
FROM   YourTable
</cfquery>

<cfoutput>#YourQuery.biggestnumber#</cfoutput>
0
 

Author Comment

by:FIATECH
ID: 20352473
well i don't want to pull the whole column. only those 6 values from that column.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 52

Expert Comment

by:_agx_
ID: 20352499
How do you identify the 6 values, by ID or are they stored as a comma delimited list, or something else?  In other words what is a sample of the table data you're using?
0
 

Author Comment

by:FIATECH
ID: 20352516
I want these only form the table

<cfset A_day04_3=getdata.A_day04_3>
<cfset A_day05_2=getdata.A_day05_2>
<cfset A_day10_4=getdata.A_day10_4>
<cfset A_day11_3=getdata.A_day11_3>
<cfset A_day12_2=getdata.A_day12_2>
<cfset A_dayothe=getdata.A_dayothe>
0
 
LVL 52

Accepted Solution

by:
_agx_ earned 500 total points
ID: 20352615
One option is use a union query

<cfquery name="getBiggestNumber" ...>
  SELECT  Max(TheNumber) AS BiggestNumber
  FROM  (
  SELECT A_day04_3 AS TheNumber FROM YourTable
  UNION
  SELECT A_day05_2 AS TheNumber FROM YourTable
  UNION
  SELECT A_day10_4 AS TheNumber FROM YourTable
  UNION
  SELECT A_day11_3 AS TheNumber FROM YourTable
  UNION
  SELECT A_day12_2 AS TheNumber FROM YourTable
  UNION
  SELECT A_dayothe AS TheNumber FROM YourTable
  ) AS t
</cfquery>

Another is to put the values into an array and use arrayMax

<cfset list = "#getdata.A_day04_3#,#getdata.A_day05_2#,#getdata.A_day10_4#,#getdata.A_day11_3#,#getdata.A_day12_2#,#getdata.A_dayothe#">
<cfset biggestnumber = arrayMax(listToArray(list))>
<cfoutput>
#biggestNumber#
</cfoutput>



0
 

Author Comment

by:FIATECH
ID: 20352634
Thanks I like the list array! THANKS! Let me try it now!
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
CFGRID Custom Functionality Series -  Part 1 Hi Guys, I was once asked how it is possible to to add a hyperlink in the cfgrid and open the window to show the data. Now this is quite simple, I have to use the EXT JS library for this and I achiev…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now