Skip to main content
Known Participant
June 23, 2008
Question

CFM and DB SubSelect SQL?

  • June 23, 2008
  • 2 replies
  • 665 views
Hello all,
Thanks for any help you can give..... but I'm working on creating an SQL search statement of an Access Database.... (Using CFM 7).
Now, I have two(2) criteria that must to be met in the SQL statement ...listed at the beginning of the SQL statement below.... but then in additon to that........ I have 4 criteria which should be retrieved if any of the 4 statements are true... (So, basically OR statements..) I've read something about Sub Selects?.... Is this type of thing something I should use...or am I going about this incorrectly? SQL commented below.
Thanks for any help you can give :)

-------------------------------------------------------------------------------------------------------------

<cfquery name="dateInfo" datasource="CaProjectNew">
SELECT * FROM CAprojectDB, mailOrder

<!-- these two need to be true -->
WHERE ((CAprojectDB.ProjectID = mailOrder.ProjectID) AND mailOrder.DMCRepID = '#searchbyfieldDMC#'

<!-- and where any one of these statements are true - OR Clauses?-->
<!-- do I use some kind of Sub Select here? -->

(#dropdate# BETWEEN #CreateODBCDate(form.startDate)# AND #CreateODBCDate(form.endDate)#))
OR (#splitdate2# BETWEEN #CreateODBCDate(form.startDate)# AND #CreateODBCDate(form.endDate)#))
OR (#splitdate3# BETWEEN #CreateODBCDate(form.startDate)# AND #CreateODBCDate(form.endDate)#))
OR (#splitdate4# BETWEEN #CreateODBCDate(form.startDate)# AND #CreateODBCDate(form.endDate)#))

<!-- optional Order Clause -->
ORDER BY mailOrder.dateAdded DESC
</cfquery>


-------------------------------------------------------------------
Tim


This topic has been closed for replies.

2 replies

Inspiring
June 24, 2008
you want your ands & ors arranged like this:

where a = b
and c = d
and
(
e = f
or
g = h
or
etc
)
tromanNMVAuthor
Known Participant
June 24, 2008
Thank you Dan!
That was perfect....

Tim :)
Participating Frequently
June 23, 2008
Are dropdate and splitdate2 through splitdate4 ColdFusion variables, or are they Access column names? If they are column names, then why do you have them enclosed in # characters, and if they aren't, then why are you comparing them to other ColdFudion variables within a query?

Phil
tromanNMVAuthor
Known Participant
June 23, 2008
Thank for you reply paross1 ,

Actually there are Database fields.... from the mailorder table.... (below?)
I'm just not sure how to add these OR statements to the And clauses...

(mailOrder.dropdate BETWEEN #CreateODBCDate(form.startDate)# AND #CreateODBCDate(form.endDate)#))
OR (mailOrder.splitdate2 BETWEEN #CreateODBCDate(form.startDate)# AND #CreateODBCDate(form.endDate)#))
OR (mailOrder.splitdate3 BETWEEN #CreateODBCDate(form.startDate)# AND #CreateODBCDate(form.endDate)#))
OR (mailOrder.splitdate4 BETWEEN #CreateODBCDate(form.startDate)# AND #CreateODBCDate(form.endDate)#))


-------------------------------
thanks again!
Tim