To define a computed field in the DataWindow editor Design
view:
Select Insert>Control>Computed Field from the menu bar.
Click where you want to place the computed field.
If the calculation is to be based on column data that changes for each row, make sure you place the computed field in the detail band.
The Modify Expression dialog box displays, listing:
DataWindow expression functions you can use in the computed field
The columns in the DataWindow object
Operators and parentheses
Enter the expression that defines the computed field as described in “Entering the expression”.
(Optional) Click Verify to test the expression.
Sybase WorkSpace analyzes the expression.
Click OK.
You can enter any valid DataWindow expression when defining a computed field. You can paste operators, columns, and DataWindow expression functions into the expression from information in the Modify Expression dialog box. Use the + operator to concatenate strings.
DataWindow expressions
You are entering a DataWindow expression, not a SQL expression
processed by the DBMS, so the expression follows the rules for DataWindow expressions.
You can refer to other rows in a computed field. This is particularly useful in N-Up DataWindow objects when you want to refer to another row in the detail band. Use this syntax:
ColumnName[x]
where x is an integer. 0 refers to the current row (or first row in the detail band), 1 refers to the next row, –1 refers to the previous row, and so on.
Table 4-1 shows some examples of computed fields.
To display |
Enter this expression |
In this band |
---|---|---|
Current date at top of each page |
|
Header |
Current time at top of each page |
|
Header |
Current page at bottom of each page |
|
Footer |
Total page count at bottom of each page |
|
Footer |
Concatenation of Fname and Lname columns for each row |
|
Detail |
Monthly salary if Salary column contains annual salary |
|
Detail |
Four asterisks if the value of the Salary column is greater than $50,000 |
|
Detail |
Average salary of all retrieved rows |
|
Summary |
Count of retrieved rows, assuming each row contains a value for EmpID |
|
Summary |
Sybase WorkSpace provides a quick way to create computed fields that summarize values in the detail band, display the current date, or show the current page number.
To summarize values:
Select one or more columns in the DataWindow object’s detail band.
Select Insert>Control from the menu bar.
Select one of the options at the bottom of the cascading menu: Average, Count, or Sum.
Sybase WorkSpace places a computed field in the summary band or in the group trailer band if the DataWindow object is grouped. The band is resized automatically to hold the computed field. If there is already a computed field that matches the one being generated, it is skipped.
To insert a computed field for the current date
or page number:
Select Insert>Control from the menu bar.
Select Today() or Page n of n from the options at the bottom of the cascading menu.
Click anywhere in the DataWindow object.
If you selected Today, Sybase WorkSpace inserts a computed field containing
this expression: Today()
. For
Page n of n, the computed field contains this expression: 'Page
' + page() + ' of ' + pageCount()
.