• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 849
  • Last Modified:

Max() function on multiple columns of a dataset

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
imonfireDAMMIT
Asked:
imonfireDAMMIT
  • 3
1 Solution
 
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
0
 
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.
0
 
imonfireDAMMITAuthor 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

    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
 
imonfireDAMMITAuthor Commented:
no
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now