Computed Values
Get Largest Field Value from a Table Column

Description
This customization shows how to get the largest field value from a table column.
Variables
Table Name
Select a database table with numeric field(s)
Numeric Field
Select a numeric field in the table
Applies to
DataAccessClass class
Code
 
''' 
''' This function gets the largest field value.
''' 
Public Function GetLargest() As Integer 

    ' Create where string 
    ' example of where clause is
    ' whereStr = " myNumericField = 1"
    ' whereStr = " myStrField = '1'"
    Dim whereStr as String = Nothing

    ' Create the order by object.
    Dim bExpandForeignKeyColumns as Boolean  = False
    Dim bIsCaseInsensitive as Boolean = False
    Dim ob as New BaseClasses.Data.OrderBy(bExpandForeignKeyColumns, bIsCaseInsensitive)
    ob.AddColumn(Me.${Numeric Field}Column, BaseClasses.Data.OrderByItem.OrderDir.Desc)

    ' Get the record.
    Dim rec As ${${Table Name}RecordClassName} = ${${Table Name}ClassName}.GetRecord(whereStr, ob)

	If Not rec Is Nothing
		' Return the largest field value.
		Return Integer.Parse(rec.${Numeric Field}.ToString())    
	End If
	   
	' If no records are available in the table, then return zero. 
	Return 0
End Function
     


  Privacy Statement