Skip to main content
Inspiring
November 30, 2013
Question

Flexible Criteria Search redux

  • November 30, 2013
  • 1 reply
  • 1284 views

This action page to query mutiple drop-down selection only works with 2 choices- when a third is introduced, it ignores it:

<cfquery name="search_flexible_criteria" datasource="#Request.BaseDSN#">

SELECT

mo.order_ID,

mo.order_number,

mo.order_property_type_ID,

mo.order_order_type_ID,

mo.order_report_type_ID,

mo.order_client_ID,

mo.order_appraiser_ID,

mo.order_status_ID,

mo.order_rush_status_ID,

mo.order_property_street,

mo.order_property_city,

mo.order_create_date,

ls.order_status_ID,

ls.order_status,

lc.client_ID,

lc.client_company,

la.appraiser_ID,

la.appraiser_fname,

la.appraiser_lname,

lo.order_type_ID,

lo.order_type,

lp.property_type_ID,

lp.property_type,

lr.report_type_ID,

lr.report_type,

lrs.rush_status_ID,

lrs.rush_status

FROM  main_orders mo

       

        LEFT JOIN lookup_order_status ls

        ON mo.order_status_ID = ls.order_status_ID

       

        LEFT JOIN lookup_clients lc

        ON mo.order_client_ID = lc.client_ID

       

       

        LEFT JOIN lookup_appraisers la

        ON mo.order_appraiser_ID = la.appraiser_ID

       

        LEFT JOIN lookup_order_type lo

        ON mo.order_order_type_ID = lo.order_type_ID

       

        LEFT JOIN lookup_property_type lp

        ON mo.order_property_type_ID = lp.property_type_ID

       

        LEFT JOIN lookup_report_type lr

        ON mo.order_report_type_ID = lr.report_type_ID

       

       

        LEFT JOIN lookup_rush_status lrs

        ON mo.order_rush_status_ID = lrs.rush_status_ID

       

        WHERE 1 = 1

<cfif StructKeyExists(Form, "StartDate") AND StructKeyExists(Form, "EndDate")  AND form.StartDate IS NOT  "" AND form.EndDate IS NOT  "">

AND (order_create_date BETWEEN #CreateODBCDate(FORM.StartDate)# AND #CreateODBCDate(FORM.EndDate)#)</cfif>

<cfif StructKeyExists(Form, "order_client_ID") AND Form.order_client_ID NEQ 0>

AND client_ID  = #Form.order_client_ID# </cfif>

<cfif StructKeyExists(Form, "order_appraiser_ID") AND Form.order_appraiser_ID NEQ 0>

AND  appraiser_ID  = #Form.order_appraiser_ID#</cfif>

<cfif StructKeyExists(Form, "order_status_ID") AND Form.order_status_ID NEQ 0>

 

AND mo.order_status_ID = #Form.order_status_ID#</cfif>

<cfif StructKeyExists(Form, "order_rush_status_ID") AND Form.order_rush_status_ID NEQ 0>

AND order_rush_status_ID = #Form.order_rush_status_ID#</cfif>

ORDER BY order_create_date DESC

</cfquery>  

Thanks to Carl for getting it this far- hair-pulling, hopefully, will stop soon.

Thank you for taking the time to read this.

Norman

This topic has been closed for replies.

1 reply

Carl Von Stetten
Legend
December 3, 2013

Norman,


Did you do what I suggested in the other thread and test the query in SSMS? Would help to isolate whether there is a problem with the SQL being generated or with the CF logic.

-Carl V.

Inspiring
December 3, 2013

Carl:

Thanks for picking this up again. Running the query directly in SQLServer:

Msg 208, Level 16, State 1, Line 1

Invalid object name 'main_orders'.

which makes no sense, since I  use that table in dozens of queries that do work.

Carl Von Stetten
Legend
December 10, 2013

Carl:

All is good in CF land- I had omitted 3 of the IF variables on the action page.

I really appreciate all the time you took helping with this- I will be debugging in SSMS from now on.

Have a great holliday :>)

Norman


Norman,

Glad you got it sorted.  Sorry for the intermittent replies over the past few days; we were moving back into our normal office space over the weekend and setting everything back up.

-Carl V.