sqlcoldfusioncoldfusion-11

How to delete a specific column from a query ColdFusion 11


I want to delete a specific column from a query. I have already tried it with queryDeleteColumn however I get the error message:

Variable QUERYDELETECOLUMN is undefined".

Here is a code snippet (ColdFusion 11.0.18):

<cfquery name="qData" datasource="datasource">
    SELECT
        *
    FROM
        table
</cfquery>
<cfset qData = QueryDeleteColumn(qData,"columnName")

Solution

  • The function queryDeleteColumn was added in ColdFusion 2018. So it wont be available in ColdFusion 11.

    You can do a query of query on the initial result like the following.

    <cfquery name="qData" datasource="datasource">
        SELECT
            *
        FROM
            table
    </cfquery>
    
    <cfif listFindNoCase(test.columnList, 'columnName')>
        <cfquery name="qData" dbtype="query">
            SELECT
              #listDeleteAt(test.columnList, listFindNoCase(test.columnList, 'columnName'))#
            FROM qData
        </cfquery>
    </cfif>