|
|
The
columns
argument indicates which columns in the specified table
should be retrieved by the specified method. The columns
argument may be a comma-delimited string, an array, or
an array literal containing column names from the specified
table. The strings "*" and "" indicate that all columns
should be retrieved.
In
the case of a table that contains lookup fields, fields
from the linked table may be returned by including columns
with the syntax LookupColumn:ForeignColumn,
where LookupColumn
is the name of the lookup column in the current table
and ForeignColumn
is the name of a column in table linked by the lookup
column.
1. |
Using
an array object:
var cols = new Array("foo",
"bar", "lookupColumn:foreignColumn");
var rs = new Resultset("MyTable", cols, "*");
return rs["lookupColumn:foreignColumn"];
|
2. |
Using
an array literal:
var rs = new Resultset("MyTable",["foo", "bar",
"lookupColumn:foreignColumn"], "*");
return rs.foo;
|
3. |
Using
a comma-delimited string:
var rs = new Resultset("MyTable",
"foo,bar,lookupColumn:foreignColumn","*");
return rs.bar;
SQL expressions may be included in the string. In the following example, a SQL expression is used to output links to those records where the RowID is less than 10.
var rs = table.select("AddressBook", "calcField =
CASE
WHEN RowID <= 10
THEN '<a href=/AddressBook/default.view?RowID='
+ String(RowID) + '>' + String(RowID) + '</a>'
ELSE
''
END", "*");
while (rs.next())
{
response.write(rs.calcField, "<br>");
}
Also aggregation functions may be included in the columns argument. The following example retrieves the maximum value of the UnitPrice field.
var rs = new Resultset("Products",
"MaxPrice = Max(UnitPrice)", "*");
if(rs.next())
response.write(rs.MaxPrice);
|
|