Solved

Max() function on multiple columns of a dataset

Posted on 2010-09-20
4
807 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]
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 is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

777 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