CFLib.org – Common Function Library Project

QueryRowFromKey(theQuery, keyField, keyFieldValue)

Last updated June 28, 2002

author

Shawn Seley

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);
}
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson