Skip to main content
Inspiring
January 29, 2007
Question

How to get fieldnames from Query

  • January 29, 2007
  • 3 replies
  • 324 views
Hello I have a query as such.

<cfquery name="q1" datasource="mydb">
Select * from tbl_test
</cfquery>

How can I get only the fieldnames from the query ?
    This topic has been closed for replies.

    3 replies

    Participating Frequently
    January 29, 2007
    <cfquery name="myQuery" datasource="yourDataSourceName" result="myResult">
    select * from tableName
    </cfquery>

    <cfoutput>
    #myQuery.ColumnList#<br>
    #myResult.ColumnList#
    </cfoutput>
    This will give the column names in alphabetical order.

    But to get the column names in the same order as in database tables, use this:
    <cfoutput>
    #ArrayToList(myQuery.getColumnList())#
    </cfoutput>

    Hope this is what you need.


    Thanks

    Sankalan
    (www.mindfiresolutions.com)
    Fernis
    Inspiring
    January 29, 2007
    <cfoutput>
    #q1.columnList#
    </cfoutput>

    Just as a reminder, you should not never use "SELECT *" unless your application really is about managing database structures, dynamically dumping a desired table data, or debugging something.

    Always define the desired column names in a SELECT clause, for the sake of performance, if you know what you want the query to return.
    Inspiring
    January 29, 2007
    #q1.ColumnList#

    http://livedocs.macromedia.com/coldfusion/7/htmldocs/00000192.htm#2712201

    --
    Ken Ford
    Adobe Community Expert
    Fordwebs, LLC
    http://www.fordwebs.com


    "Like2Flex" <webforumsuser@macromedia.com> wrote in message news:epkv4a$lsv$1@forums.macromedia.com...
    > Hello I have a query as such.
    >
    > <cfquery name="q1" datasource="mydb">
    > Select * from tbl_test
    > </cfquery>
    >
    > How can I get only the fieldnames from the query ?