QueryRowFromKey(theQuery, keyField, keyFieldValue)
Last updated June 28, 2002
Version: 1 | Requires: CF5 | Library: DataManipulationLib
Description:
Returns the first query row number that contains the specified key value. Useful when using functions that require a query's row number ... but you only have its primary key (or any other value that identifies the record). Returns zero if no matching keyFieldValue is found.
Return Values:
Returns a numeric value.
Example:
<CFSET my_query = QueryNew("Username,Name,Age")>
<CFSET QueryAddRow(my_query, 1)>
<CFSET QuerySetCell(my_query,"Username", "CUser")>
<CFSET QuerySetCell(my_query,"Name","Chris User")>
<CFSET QuerySetCell(my_query,"Age", 30)>
<CFSET QueryAddRow(my_query, 1)>
<CFSET QuerySetCell(my_query,"Username", "AUser")>
<CFSET QuerySetCell(my_query,"Name","Albert User")>
<CFSET QuerySetCell(my_query,"Age", 10)>
<CFSET QueryAddRow(my_query, 1)>
<CFSET QuerySetCell(my_query,"Username", "BUser")>
<CFSET QuerySetCell(my_query,"Name","Brad User")>
<CFSET QuerySetCell(my_query,"Age", 20)>
<cfoutput>
Query:<br>
<br>
<CFDUMP VAR="#my_query#">
<br>
<br>
Row number with username of "AUser" = <b>#QueryRowFromKey(my_query, "Username", "AUser")#</b>
</cfoutput>
Parameters:
Name | Description | Required |
---|---|---|
theQuery | The query to search. | Yes |
keyField | The column to search. | Yes |
keyFieldValue | The value to search for. | Yes |
Full UDF Source:
/**
* Returns the first query row number that contains the specified key value.
*
* @param theQuery The query to search. (Required)
* @param keyField The column to search. (Required)
* @param keyFieldValue The value to search for. (Required)
* @return Returns a numeric value.
* @author Shawn Seley (shawnse@aol.com)
* @version 1, June 28, 2002
*/
function QueryRowFromKey(theQuery, keyField, keyFieldValue){
var key_field_value_list = Evaluate("ValueList(theQuery.#keyField#)");
return ListFindNoCase(key_field_value_list, keyFieldValue);
}
Search CFLib.org
Latest Additions
Raymond Camden added
QueryDeleteRows
November 04, 2017
Leigh added
nullPad
May 11, 2016
Raymond Camden added
stripHTML
May 10, 2016
Kevin Cotton added
date2ExcelDate
May 05, 2016
Raymond Camden added
CapFirst
April 25, 2016