CFSelect Multiple and ListQualify

If you need a multiple selection list and need to display its values dynamically from a query you can do this in one line of code within your form.

<cfquery name="getstatus" datasource="myDSN">
select All as status from orderstable
UNION ALL
select distinct status from orderstable
</cfquery>
 
<cfform ...>
<cfselect name="status" query="getstatus" value="status" multiple="yes" />
...
</cfform>

The result is a form with a multiple selection of order statuses .

To use the selected statuses after form submission you write the query using ListQualify, that returns a copy of the list, with qualifier (singlequotes) before and after the specified element(s).
I also set a default cfparam for status=”All”
<cfparam name="Form.status" default="All">
<cfquery name="getdata" datasource="myDSN">
select * from orderstable
<cfif #FORM.tkt_status# neq "All">where status in (#ListQualify(FORM.status,"'")#)</cfif>
</cfquery>

Cup size   
Select size then click on coffee cup.
This entry was posted in Code, Coldfusion, Snippets, SQL. Bookmark the permalink.