Finding maximum value from a series...
-
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
-
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
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
-
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
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
-
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
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. -
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.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
-
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
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; } -
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; }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
-
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
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