Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Finding maximum value from a series...

Finding maximum value from a series...

Scheduled Pinned Locked Moved Visual Basic
databasecsharphelptutorial
8 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mayhem_rules
    wrote on last edited by
    #1

    VB.net / sql. Consider I have a table in sql with fields A to F each storing an integer value. I need to find the maximum value from the fields. Can anyone help me with this. Can this be done through a sql query? if yes, then how and if not then how to find the maximum value through program. plz help fast... With Best Regards, Mayur

    T J 2 Replies Last reply
    0
    • M mayhem_rules

      VB.net / sql. Consider I have a table in sql with fields A to F each storing an integer value. I need to find the maximum value from the fields. Can anyone help me with this. Can this be done through a sql query? if yes, then how and if not then how to find the maximum value through program. plz help fast... With Best Regards, Mayur

      T Offline
      T Offline
      Tamimi Code
      wrote on last edited by
      #2

      hi if you want to select the max value in the column A : SqlSelectCommand1 = New System.Data.SqlClient.SqlCommand("select max(A)from TableName", SqlConnection1) SqlConnection1.Open() Dim max As Integer = CType(SqlSelectCommand1.ExecuteScalar(), Integer) SqlConnection1.Close() Tamimi - Code

      M 1 Reply Last reply
      0
      • T Tamimi Code

        hi if you want to select the max value in the column A : SqlSelectCommand1 = New System.Data.SqlClient.SqlCommand("select max(A)from TableName", SqlConnection1) SqlConnection1.Open() Dim max As Integer = CType(SqlSelectCommand1.ExecuteScalar(), Integer) SqlConnection1.Close() Tamimi - Code

        M Offline
        M Offline
        mayhem_rules
        wrote on last edited by
        #3

        thnx for your reply. However, I do not want to find the max value from a particular field. I need to find the maximum of the value from the fields A to F. say A has a value 1, B-2, C-3, D-4, E-5, F-3, then I need to find the value 5 using a query or a piece of code. Remember A, B, C, D, E & F are field names and not records. With Best Regards, Mayur

        R 1 Reply Last reply
        0
        • M mayhem_rules

          thnx for your reply. However, I do not want to find the max value from a particular field. I need to find the maximum of the value from the fields A to F. say A has a value 1, B-2, C-3, D-4, E-5, F-3, then I need to find the value 5 using a query or a piece of code. Remember A, B, C, D, E & F are field names and not records. With Best Regards, Mayur

          R Offline
          R Offline
          Robert Rohde
          wrote on last edited by
          #4

          Well then execute the query 6 times or just make one select to get the maximum of all fields together and then use Math.Max to determine the biggest ones among these.

          M 1 Reply Last reply
          0
          • R Robert Rohde

            Well then execute the query 6 times or just make one select to get the maximum of all fields together and then use Math.Max to determine the biggest ones among these.

            M Offline
            M Offline
            mayhem_rules
            wrote on last edited by
            #5

            Thnx Robert. Maybe I will try and explain it once again. Consider a table having A - Z fields storing integer values. Therefore each record in this table will have A - Z fields. I need to find the maximum value for each record from the fields A - Z. Can you plz help me with this. With Best Regards, Mayur

            G 1 Reply Last reply
            0
            • M mayhem_rules

              Thnx Robert. Maybe I will try and explain it once again. Consider a table having A - Z fields storing integer values. Therefore each record in this table will have A - Z fields. I need to find the maximum value for each record from the fields A - Z. Can you plz help me with this. With Best Regards, Mayur

              G Offline
              G Offline
              Guffa
              wrote on last edited by
              #6

              There is no simple way of doing that, as the database is badly designed. For the fields A to C, it would be select case when A > B then (case when A > C then A else C end) else (case when B > C then B else C end) end from ... Imagine what that would look like for A to Z... The query would most likely be too complex to even run... The values should be stored in separate records (in a separate table) if you want to be able to aggregate them efficiently. --- b { font-weight: normal; }

              M 1 Reply Last reply
              0
              • G Guffa

                There is no simple way of doing that, as the database is badly designed. For the fields A to C, it would be select case when A > B then (case when A > C then A else C end) else (case when B > C then B else C end) end from ... Imagine what that would look like for A to Z... The query would most likely be too complex to even run... The values should be stored in separate records (in a separate table) if you want to be able to aggregate them efficiently. --- b { font-weight: normal; }

                M Offline
                M Offline
                mayhem_rules
                wrote on last edited by
                #7

                Thanks Guffa. I understand what you mean to say. Can you suggest a way this can be done using vb.net. As in reading a record and then finding the maximum value through code... With Best Regards, Mayur

                1 Reply Last reply
                0
                • M mayhem_rules

                  VB.net / sql. Consider I have a table in sql with fields A to F each storing an integer value. I need to find the maximum value from the fields. Can anyone help me with this. Can this be done through a sql query? if yes, then how and if not then how to find the maximum value through program. plz help fast... With Best Regards, Mayur

                  J Offline
                  J Offline
                  J4amieC
                  wrote on last edited by
                  #8

                  You have badly designed the database, and there is no easy way to aggregate this data. Maybe you could explain what you are trying to achieve, and somebody could make some suggestions on how to go about it better. Current blacklist svmilky - Extremely rude | FeRtoll - Rude personal emails | ironstrike1 - Rude & Obnoxious behaviour

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups