Max() function on multiple columns of a dataset

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))
Who is Participating?
imonfireDAMMITConnect With a Mentor Author Commented:
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

      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

      Return CInt(objLevelMAX)
Guy Hengel [angelIII / a3]Billing EngineerCommented:
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
imonfireDAMMITAuthor Commented:
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.
imonfireDAMMITAuthor Commented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.