Was this helpful?
Query Assignments
This type of assignment statement uses a query to assign a list of values from the database to several or all simple fields on a form, to the rows of a table field, to record attributes, or to an array. In a query assignment, you use a select statement. You can optionally include a submenu.
For details on constructing queries, see Select.
Examples
The following examples show direct assignments.
Assign given values to the Name and Empnum simple fields of the form:
name := 'John';
empnum := 35;
Assign specified values to the columns Name and Age in the second row of the table field named Child. The integer expression "2" refers to a row in the table-field display in the window, not to a record in the underlying data set.
child[2].name := 'Sally';
child[2].age := 8;
Place the specified values in the Name and Age columns in the current row of the table field named Child:
child.name := 'Steven'; 
child.age := 11;
Assign specified values to the name and salary attributes of the record employee:
employee.name := 'John' ;
employee.salary := 50000 ;
Assign specified values to the name and address attributes in the third row of the array named parent. The integer expression 3 refers to a record in the array, not to a visible field on a form.
parent[3].name := 'Janet' ;
parent[3].address := 'New York' ;
The next examples show query assignments:
Assigns Name and Cost from the Objects table to the array pricearr, based on the color of the objects:
pricearr = select name, cost 
  from objects 
  where objects.color = 'RED';
The following statement retrieves values from the Projects table to simple fields on the form Empform. The value from the column Projname is assigned to the Task field, while the value from the Hours column is assigned to the Time field. As a simple field assignment, this statement reads one record from the database table.
empform := select task = projname, 
  time = hours 
  from projects;
The following select query reads multiple records selected from the database table Parts into a data set associated with the table field partstbl.
partstbl := select number, name, price 
  from parts;
The examples below show query assignments to an array record and to a table field row. Note the differences in syntax.
The following example reads the columns name, job_title, and ssno from the Employees table for the record whose value for ssno is '555-55-5555'. They are read into the attributes name, job_title, and ss for the first record in the array emparr. This array has another attribute, salary, which is set to 0.
emparr[1] := select name, job_title, 
    ss = ssno
  from employees
  where ssno = '555-55-5555';
This example reads the columns name, job_title, and ssno from the Employees table for the record whose value for ssno is '555-55-5555'. They are read into the table field columns name, job_title, and ss for the current row of the table field. The cursor must be in the table field for this query to succeed. This row of emptbl has another attribute, salary, which is cleared.
emptbl := select name, job_title, 
    ss = ssno
  from employees
  where ssno = '555-55-5555';
Last modified date: 04/03/2024