Min max from Dataset

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?RGFu?=

    Min max from Dataset

    I have a data set that I would like to get the min max for a column but only
    from a range of records ie the 20th thru the 33rd record. Could someone point
    me to some sytax to do this.

    Thanks in advance - Dan
  • DaveL

    #2
    Re: Min max from Dataset

    somthing like the below

    select min(somecolumn) , max(SomeColumn) from sometable (nolock)

    where somecolumn >= somvalue and somecolumn <= somvalue

    look at the Sql Between clause also

    DaveL



    "Dan" <Dan@discussion s.microsoft.com wrote in message
    news:A81B1ADF-D520-40A7-B50B-7B2971793E41@mi crosoft.com...
    >I have a data set that I would like to get the min max for a column but
    >only
    from a range of records ie the 20th thru the 33rd record. Could someone
    point
    me to some sytax to do this.
    >
    Thanks in advance - Dan

    Comment

    • maximz2005

      #3
      Re: Min max from Dataset

      On Aug 21, 2:29 pm, "DaveL" <dvs_...@sbcglo bal.netwrote:
      somthing like the below
      >
      select min(somecolumn) , max(SomeColumn) from sometable  (nolock)
      >
      where somecolumn >= somvalue and somecolumn <= somvalue
      >
      look at the Sql Between clause also
      >
      DaveL
      >
      "Dan" <D...@discussio ns.microsoft.co mwrote in message
      >
      news:A81B1ADF-D520-40A7-B50B-7B2971793E41@mi crosoft.com...
      >
      I have a data set that I would like to get the min max for a column but
      only
      from a range of records ie the 20th thru the 33rd record. Could someone
      point
      me to some sytax to do this.
      >
      Thanks in advance - Dan
      Sorry, could you elaborate on what you want to achieve?
      If I understand correctly, you're trying to get the row that has the
      minimum value for some column in a table, and the same thing for the
      row that has the maximum value.
      DaveL posted code to get the value from a SQL Server database, but you
      have a dataset, so it's much different (and easier!)
      I'll post some code ASAP.

      Also, if you do it your own way, don't forget to cast the values to an
      int, so that C# knows how to compare the values.

      Comment

      • KWienhold

        #4
        Re: Min max from Dataset

        On 21 Aug., 22:55, Dan <D...@discussio ns.microsoft.co mwrote:
        I have a data set that I would like to get the min max for a column but only
        from a range of records ie the 20th thru the 33rd record. Could someone point
        me to some sytax to do this.
        >
        Thanks in advance - Dan
        I'm assuming you mean DataTable, otherwise the question is not quite
        clear.
        If the values you want to compare are ints, something like this should
        work:

        for (int i = startIndex; i <= endIndex; i++)
        {
        int value = Convert.ToInt32 (table.Rows[i].ItemArray[columnIndex]);

        if (value highest)
        {
        highest = value;
        }
        else if (value < lowest)
        {
        lowest = value;
        }
        }

        hth,
        Kevin Wienhold

        Comment

        Working...