QuerySort(query, column[, sortDir ])
Last updated October 15, 2002
Version: 2 | Requires: CF6 | Library: DataManipulationLib
Description:
Sorts a query using Query of Query.
Return Values:
Returns a query.
Example:
<cfquery name="getit" datasource="cflib" maxrows=4>
select name,id from tblUDFs
order by id desc
</cfquery>
<cfdump var="#getIt#" label="Before Sort">
<cfdump var="#querySort(getit,"name")#" label="After Sort">
Parameters:
Name | Description | Required |
---|---|---|
query | The query to sort. | Yes |
column | The column to sort on. | Yes |
sortDir | The direction of the sort. Default is "ASC." | No |
Full UDF Source:
<!---
Sorts a query using Query of Query.
Updated for CFMX var syntax.
@param query The query to sort. (Required)
@param column The column to sort on. (Required)
@param sortDir The direction of the sort. Default is "ASC." (Optional)
@return Returns a query.
@author Raymond Camden (ray@camdenfamily.com)
@version 2, October 15, 2002
--->
<cffunction name="QuerySort" output="no" returnType="query">
<cfargument name="query" type="query" required="true">
<cfargument name="column" type="string" required="true">
<cfargument name="sortDir" type="string" required="false" default="asc">
<cfset var newQuery = "">
<cfquery name="newQuery" dbType="query">
select * from query
order by #column# #sortDir#
</cfquery>
<cfreturn newQuery>
</cffunction>
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