macromedia.coldfusion.cfml_general_discussion
[Top] [All Lists]

Re: building dynamic query

Subject: Re: building dynamic query
From: Shane_Z
Date: Thu, 30 Aug 2007 07:53:30 -0700
Newsgroups: macromedia.coldfusion.cfml_general_discussion
To me it looks like you had it mostly correct.  Here is how I would
restructure the query, but since I do not have a datasource to run it
against I have not tested it.  Since you will only be sorting on one
column, the commas that were in the original query should not be
required, which is basically the only change made to your original
query.

<cfquery name="get" datasource="weblog" username="#dsn_username#"
password="#dsn_password#">
     SELECT *
     FROM table1
    <!--- where staffid = #name.staffid#  --->
        <cfif isdefined("sort")>
            ORDER BY
        <cfif sort eq "staffname">
            staffid
        </cfif>
        <cfif sort eq "taskname">
           priority
        </cfif>
        <cfif sort eq "dateset">
            dateset
        </cfif>
        <cfif sort eq "completiondate">
          completiondate
        </cfif>
        <cfif sort eq "isdone">
           isdone
        </cfif>
    </cfif>
 </cfquery>


<Prev in Thread] Current Thread [Next in Thread>