Description

This function checks the query for a column with the same name as the key provided.

Returns

True if a matching column exists, false otherwise.

Category

Query functions

History

New in Adobe ColdFusion (2016 release)

See also

QuerySortQueryFilterQueryEach

Syntax

boolean QueryKeyExists(Object query, String key)

Parameters

Parameter Description
query (Required) Query to be checked whether a key is available.
key (Required) Key to be matched with the columns.

Example

<cfquery 
       name="courses" datasource="cfdocexamples" 
       cachedwithin="#CreateTimeSpan(0, 6, 0, 0)#"> 
       SELECT CORNUMBER,DEPT_ID,COURSE_ID,CORNAME 
       FROM COURSELIST 
</cfquery> 

<cfscript> 
    //Use an absolute path for the files. -
    theDir=GetDirectoryFromPath(GetCurrentTemplatePath()); 
    theFile=theDir & "courses.xls"; 
    //Create two empty ColdFusion spreadsheet objects
    theSheet = SpreadsheetNew("CourseData"); 
   SpreadsheetAddRows(theSheet,courses); 
    
</cfscript> 
 
<!--- Write the two sheets to a single file ---> 
<cfspreadsheet action="write" filename="#theFile#" name="theSheet"  
    sheetname="courses" overwrite=true> 
<cfspreadsheet action="read" src="#theFile#" sheetname="courses" query="queryData"> 

<cfoutput>querydata.KeyExists("col_1"):#querydata.KeyExists("col_1")#</cfoutput>

Using member function

<cfscript>
       myResult=QueryExecute("SELECT * FROM EMPLOYEES",[],{datasource="cfdocexamples"});
       status=myResult.keyexists("LOCATION");
       if (status=="YES"){
             WriteOutput("Matching column exists: "& status);
       }
       else{
             WriteOutput("Matching column exists: "& status);
       }
</cfscript>

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy