Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.
-
paross1 #1
Re: Dynamic Filtering?
Maybe something like this?
SELECT your_columns
FROM your_table
<cfif selected_state NEQ 0>WHERE State_ID = #selected_state # </cfif>
paross1 Guest
-
Filtering & displaying dynamic information
I want to create a Flash file so a user can check boxes to filter what images are displayed--the (unfiltered) images would come from an XML file.... -
Filtering a recordset
Hi, I have a database query that pulls out records from a business directory database. In the DB are fields like ratings, company name, and... -
Row filtering
Hi all, I am having a dataset which is Reading from the XML file. The Dataset has a table Users with Scheema (US_ID, US_Name). I am attempting to... -
Filtering Question
When I do a filter by selection I can see that the filter expresion in the properties box is ((.ShowName="World Shoe Association")) I would like... -
Filtering
Lets say I have a privilege structure organized by number: 1 - Administrator 2 - Office 3 - Supervisor 4 - Field Operator 5 - Assistant... -
Novian #2
Re: Dynamic Filtering?
Hi Paross1,
Thanks for the reply. I'll give it a try. Is the idea that only the IF
statements that evaluate true will be executed? What about stringing together
the IF statements that return true? For example:
SELECT your_columns
FROM your_table
<cfif selected_state NEQ 0>WHERE State_ID = #selected_state # </cfif>
<cfif selected_country NEQ 0>WHERE Country_ID = #selected_country # </cfif>
<cfif selected_region NEQ 0>WHERE Region_ID = #selected_region # </cfif>
or would I write
SELECT your_columns
FROM your_table
<cfif selected_state NEQ 0>WHERE State_ID = #selected_state # </cfif> AND
<cfif selected_country NEQ 0>WHERE Country_ID = #selected_country # </cfif> AND
<cfif selected_region NEQ 0>WHERE Region_ID = #selected_region # </cfif>
Thanks again.
Novian Guest
-
rmaglies #3
Re: Dynamic Filtering?
You can structure the where clause as follows to make the 'ands' easier
SELECT your_columns
FROM your_table
Where 1=1
<cfif #selected_state# NEQ 0>and State_ID = #selected_state # </cfif>
<cfif #selected_country# NEQ 0>and Country_ID = #selected_country # </cfif>
<cfif #selected_region# NEQ 0>and Region_ID = #selected_region # </cfif>
the 1=1 is always true, so any number of 'anded' where clauses can be added
after that
This way the 'ALL' selection can be used in any of the fields and the query
will return the correct result
rmaglies Guest
-
Novian #4
Re: Dynamic Filtering?
Originally posted by: rmaglies
You can structure the where clause as follows to make the 'ands' easier
SELECT your_columns
FROM your_table
Where 1=1
<cfif #selected_state# NEQ 0>and State_ID = #selected_state # </cfif>
<cfif #selected_country# NEQ 0>and Country_ID = #selected_country # </cfif>
<cfif #selected_region# NEQ 0>and Region_ID = #selected_region # </cfif>
the 1=1 is always true, so any number of 'anded' where clauses can be added
after that
This way the 'ALL' selection can be used in any of the fields and the query
will return the correct result
Hey rmaglies,
Yeah, that's what I ended up doing although I didn't use the 'Where 1=1'. Is
this necessary? If so, why?
I really appreciate your input as well as that of paross1. I've been learning
so much via members like you and books from guys like Ben Forta.
Thanks again.
Novian
Novian Guest
-
paross1 #5
Re: Dynamic Filtering?
Look at what happens if you don't include WHERE 1 = 1 and all three of your
variables happen to equal 0 at the same time. You would have a query with an
empty WHERE clause, which will throw a database error. Including the 1=1 it
causes two behaviors, it prevents an error if your parameters are all 0, and
your query returns all rows (kind of a default ALL).
Phil
paross1 Guest



Reply With Quote

