Solved

Max() function on multiple columns of a dataset

Posted on 2010-09-20
4
791 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
  • 3
4 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
no
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

771 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

15 Experts available now in Live!

Get 1:1 Help Now