CFLib.org – Common Function Library Project

QuerySort(query, column[, sortDir ])

Last updated October 15, 2002

author

Raymond Camden

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>
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