CFLib.org – Common Function Library Project

UniqueValueList(queryname, columnname [, cs])

Last updated March 27, 2007

Version: 1 | Requires: ColdFusion 5 | Library: DataManipulationLib

 
Rated 9 time(s). Average Rating: 4.9

Description:
Returns a list of unique values from a query column with the option of case sensitive or not.

Return Values:
Returns a string.

Example:

view plain print about
--Not Case sensitive
#uniqueValueList(queryName, "queryColumn")#

-- Case Sensitive
#uniqueValueList(queryName, "queryColumn", 1)#

Parameters:

Name Description Required
queryname Query to scan. Yes
columnname Column to use. Yes
cs If true, the unique list will check the case of the values. Defaults to false. No

Full UDF Source:

view plain print about
<cfscript>
/**
 * Returns a list of unique values from a query column.
 * 
 * @param queryname      Query to scan. (Required)
 * @param columnname      Column to use. (Required)
 * @param cs      If true, the unique list will check the case of the values. Defaults to false. (Optional)
 * @return Returns a string. 
 * @author Nick Giovanni (ngiovanni@gmail.com) 
 * @version 1, March 27, 2007 
 */

function uniqueValueList(queryName, columnName) {
    var cs = 0; 
    var curRow = 1;
    var uniqueList = "";  
    
    if(arrayLen(arguments) GTE 3 AND isBoolean(arguments[3])) cs = arguments[3]; 
    
    for(; curRow LTE queryName.recordCount; curRow = curRow +1){
        if((not cs AND not listFindNoCase(uniqueList, trim(queryName[columnName][curRow]))) OR (cs AND not listFind(uniqueList, trim(queryName[columnName][curRow])))){
            uniqueList = ListAppend(uniqueList, trim(queryName[columnName][curRow]));
        }
    }
    return uniqueList; 
}
</cfscript>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Tayo Akinmade Tayo Akinmade added
arrayTrim
4 day(s) ago

Will Belden Will Belden added
longTime
9 day(s) ago

James Sleeman James Sleeman added
quickSort
19 day(s) ago

Ben Forta Ben Forta added
GetHostAddress
22 day(s) ago

Top Rated

Darwan Leonardo Sitepu EksporSQLData
Rated 5.0, 16 time(s)

Darwan Leonardo Sitepu backupDatabase
Rated 5.0, 13 time(s)

Barney Boisvert indentXml
Rated 5.0, 10 time(s)

Kevin Pepperman generateSsccAsn
Rated 5.0, 4 time(s)

Created by Raymond Camden / Design by Justin Johnson