Parameter
This function checks the query for a column with the same name as the key provided.
True if a matching column exists, false otherwise.
Category
History
ColdFusion (2018 release): Introduced named parameters.
New in Adobe ColdFusion (2016 release)
See also
boolean QueryKeyExists(Object query, String column)
|
Parameter |
Description |
|
query |
(Required) Query to be checked whether a key is available. |
|
column |
(Required) Key to be matched with the columns. |
<cfscript>
myQuery = queryNew("id,name,amount","Integer,Varchar,Integer",
[
{id=1,name="One",amount=15},
{id=2,name="Two",amount=18},
{id=3,name="Three",amount=32}
]);
status=QueryKeyExists(myquery,"amount");
if (status=="YES"){
writeOutput("Matching column exists: "& status);
}
else{
writeOutput("Matching column exists: "& status);
}
</cfscript>
<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>
<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>
Sign in to your account