?
Solved

Max() function on multiple columns of a dataset

Posted on 2010-09-20
4
Medium Priority
?
828 Views
Last Modified: 2012-08-14
Hello,
I was wondering if there was an easier way to do what I need to do...
I have a dataset with 19 columns. One column is a date column and all the other columns are data columns containing integer values. I want to find out what the Maximum value is of the entire dataset, excluding the date column.

Max(Max(col1), (Max(col2), ...(Max(coln))
0
Comment
Question by:imonfireDAMMIT
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 33719826
I wrote some function like this :create function dbo.MyMaxIntFunction(@val1 int, @var2 int, @val3 int, @val4 int )returns intbegin  declare @t table ( result int )  insert into @t values (@val1)  insert into @t values (@val2)  insert into @t values (@val3)  insert into @t values (@val4)  return ( select max(result) from @t where result is not null )endand you can use that like this:select dbo.GetMyMaxInFunction(col1, col2, col3, col4 ) from yourtable
0
 
LVL 1

Author Comment

by:imonfireDAMMIT
ID: 33724316
the thing is I wont know how many colums are in the table. I just need to know what the largest number in the table is.
0
 
LVL 1

Accepted Solution

by:
imonfireDAMMIT earned 0 total points
ID: 34946975
I wrote a function to achieve what I needed so I figured that I would post it here...
I am writing graphing functions where data is ported into excel and graphs are created.


 Dim dcGraphData As DataColumn
    Dim objLevel As Object = Nothing
    Dim objLevelMAX As Object = Nothing

    Try
      For Each dcGraphData In GraphData.Tables(0).Columns
        objLevel = GraphData.Tables(0).Compute("Max(" & dcGraphData.ToString & ")", String.Empty)
        If Not IsDate(objLevel) And IsNumeric(objLevel) Then
          If CInt(objLevel) >= CInt(objLevelMAX) Then
            objLevelMAX = objLevel
          End If
        End If
      Next

      Return CInt(objLevelMAX)
0
 
LVL 1

Author Closing Comment

by:imonfireDAMMIT
ID: 34986559
no
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

765 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