The AddToFields method adds one or more fields to the SELECT clause of a SQL statement. This saves having to parse the statement and doing string manipulation to insert the fields at the correct spot. This method can be called, for example, from the Select script of a table to automatically add additional fields you may need for post-processing. You should also use AddToFields if you add additional filter conditions to the report using the FilterConditions collection (for example, in DataEngine.FinalizeSQLStatement) and the fields filtered on aren't already in the SELECT clause.

Syntax

AddToFields(SQLStatement as String, Fields as String) as String

Parameters
SQLStatement
The SQL statement to add fields to.

Fields
A comma-delimited list of fields to add to the SELECT clause.

Return Value
The SQL statement with the fields added to the SELECT clause.

Example

This example, called from DataEngine.FinalizeSQLStatement, adjusts the query so the user can only see active records.

Visual FoxPro

lparameters toApplication as SQApplication, tcSelect
local loCondition, lcSelect
loCondition = toApplication.DataEngine.FilterConditions.AddItem('COMPANY.ACTIVE')
if toApplication.DataEngine.FilterConditions.Count > 0
  loCondition.Connection = ') and '	
endif
loCondition.Operator = 'is Yes'
loCondition.IncludeInDisplay = .F.
lcSelect = toApplication.DataEngine.AddToFields(tcSelect, ;
  'COMPANY.ACTIVE')
return lcSelect

VBScript

function Main(Application, SelectStatement)
dim Condition
Condition = Application.DataEngine.FilterConditions.AddItem("COMPANY.ACTIVE")
if Application.DataEngine.FilterConditions.Count > 0 then
  Condition.Connection = ") and "
end if
Condition.Operator = "is Yes"
Condition.IncludeInDisplay = False
Main = Application.DataEngine.AddToFields(SelectStatement, _
  "COMPANY.ACTIVE")
end function

JavaScript

function Main(Application, SelectStatement) {
var Condition, Select ;
Condition = Application.DataEngine.FilterConditions.AddItem("COMPANY.ACTIVE") ;
if (Application.DataEngine.FilterConditions.Count > 0)
  Condition.Connection = ") and " ;
Condition.Operator = "is Yes" ;
Condition.IncludeInDisplay = false ;
Select = Application.DataEngine.AddToFields(SelectStatement, 
  "COMPANY.ACTIVE") ;
return Select ;
}

C#

public static string DataEngine_FinalizeSQLStatement(SFQApplication sfqApplication, 
  string selectStatement)
{	
  string newSelect = String.Empty;

  // Please note that any changes you make to this item will only be saved in
  // Stonefield Query after you call the Dispose() method or by using the 'using'
  // syntax below which calls Dispose() for you automatically
  using(FilterCondition condition = 
    sfqApplication.DataEngine.FilterConditions.AddItem("COMPANY.ACTIVE"))
  {
    if (sfqApplication.DataEngine.FilterConditions.Count > 0)
    {
      condition.Connection = ") and ";
    }

    condition.Operator = "is Yes";
    condition.IncludeInDisplay = false;
    newSelect = sfqApplication.DataEngine.AddToFields(selectStatement, 
      "COMPANY.ACTIVE");
  }
  return newSelect;
}

VB.NET

public shared function DataEngine_FinalizeSQLStatement(sfqApplication as _
    SFQApplication, selectStatement as string) as string
  Dim newSelect as string = String.Empty
    
  ' Please note that any changes you make to this item will only be saved in
  ' Stonefield Query after you call the Dispose() method or by using the 
  '  "using" syntax below which calls Dispose() for you automatically
  Using condition as _
    FilterCondition = sfqApplication.DataEngine.FilterConditions.AddItem("COMPANY.ACTIVE")
    if sfqApplication.DataEngine.FilterConditions.Count > 0
      condition.Connection = ") and "
    End If

    condition.Operator = "is Yes"
    condition.IncludeInDisplay = false
    newSelect = sfqApplication.DataEngine.AddToFields(selectStatement, _
      "COMPANY.ACTIVE")
  End Using
  return newSelect
End Function

See also

DataEngine Object | AddToWhere | DataEngine.FinalizeSQLStatement | FilterConditions Collection | Select

© Stonefield Software Inc., 2023 • Updated: 06/06/16
Comment or report problem with topic