QuerySlice

Returns a subset of rows from an existing query

Method Signature

QuerySlice(query=[query], offset=[integer], length=[integer])

Arguments

Argument
Type
Required
Description
Default

query

query

true

The query object to which the rows should be returned.

offset

integer

true

The first row to include in the new query.

length

integer

false

The number of rows to include, defaults to all remaining rows.

0

Examples

Create a query with 4 rows and return a new query containing the 2nd and 3rd rows of the first

Run Example

data = [ 
	[
		1,
		"James"
	],
	[
		2,
		"Alfred"
	],
	[
		3,
		"Amisha"
	],
	[
		4,
		"Terri"
	]
];
myQuery = QueryNew( "ID,name", "integer,varchar", data );
result = QuerySlice( myQuery, 2, 2 );
writeDump( var="#result#" );

Using a member function

Run Example

data = [ 
	[
		1,
		"James"
	],
	[
		2,
		"Alfred"
	],
	[
		3,
		"Amisha"
	],
	[
		4,
		"Terri"
	]
];
myQuery = QueryNew( "ID,name", "integer,varchar", data );
result = myQuery.slice( 2, 2 );
writeDump( var="#result#" );

Additional Examples

Run Example

people = QueryNew( "name,dob,age", "varchar,date,int", [ 
	[
		"Susi",
		CreateDate( 1970, 1, 1 ),
		0
	],
	[
		"Urs",
		CreateDate( 1995, 1, 1 ),
		0
	],
	[
		"Fred",
		CreateDate( 1960, 1, 1 ),
		0
	],
	[
		"Jim",
		CreateDate( 1988, 1, 1 ),
		0
	]
] );
Dump( var=people, label="people - original query" );
/* Output:
 *
 * | name | dob                 | age |
 * ------------------------------------
 * | Susi | 1970-01-01 00:00:00 | 0   |
 * | Urs  | 1995-01-01 00:00:00 | 0   |
 * | Fred | 1960-01-01 00:00:00 | 0   |
 * | Jim  | 1988-01-01 00:00:00 | 0   |
 *
 */
// paging
qrySlice = people.slice( 3, 2 );
dump( var=qrySlice, label="qrySlice - from record 3, 2 records" );
 /* Output:
 * | name | dob                 | age |
 * ------------------------------------
 * | Fred | 1960-01-01 00:00:00 | 0   |
 * | Jim  | 1988-01-01 00:00:00 | 0   |
 */

Last updated

Was this helpful?