In my database I have a datediscontinued. When someone runs a a report they select a start date (FORM.StartDate) and an end date (FORM.EndDate). I need to find the records where date discontinued is between the start and end date. If the start date is NEQ to the end date I need to find if there is another entry with a discontinued date and if not then output the entries that have a NULL endate.
I have tried a bunch of different ways. But I can't seem to wrap my head around the right logic/ and syntax to follow. what I a trying now os
<cfset startdate = createDate(2012, 02, 01)>
<cfset enddate = createDate(2012, 02, 03)>
<cfset stop = false>
<cfset go = false>
<cfoutput>#dateFormat(startdate, "MMMM DD, YYYY")# - #dateFormat(enddate, "MMMM DD, YYYY")#<br /></cfoutput>
<cfquery datasource="residents#Session.facility#" name="slide">
SELECT *
FROM slidingscale
Where who = 20 and discontinued = 1
ORDER BY datediscontinued, beginning asc
</cfquery>
<cfif slide.RecordCount NEQ 0>
<cfquery datasource="residents#Session.facility#" name="slide">
SELECT *
FROM slidingscale
Where who = 20 and datediscontinued >= #startdate#
ORDER BY datediscontinued, beginning asc
</cfquery>
<cfloop query="slide">
<cfif slide.datediscontinued eq enddate>
<cfoutput>
#slide.beginning# - #slide.ending# <cfif slide.datediscontinued NEQ "">#dateformat(slide.datediscontinued, "mmmm dd, yyyy")#</cfif><br>
</cfoutput>
<cfelseif slide.datediscontinued gte startdate>
<cfoutput>
#slide.beginning# - #slide.ending# <cfif slide.datediscontinued NEQ "">#dateformat(slide.datediscontinued, "mmmm dd, yyyy")#</cfif><br>
</cfoutput>
</cfif>
</cfloop>
</cfif>
February 01, 2012 - February 03, 2012
query
RESULTSET
query
BEGINNING DATEDISCONTINUED DISCONTINUED DOSE ENDING ID MEDNAME WHO
1 0 [empty string] 0 11 100 46 Insulin 20
2 101 [empty string] 0 22 150 47 Insulin 20
3 151 [empty string] 0 33 200 48 Insulin 20
4 201 [empty string] 0 44 250 49 Insulin 20
5 0 {ts '2012-02-03 00:00:00'} 1 11 100 39 Insulin 20
6 101 {ts '2012-02-03 00:00:00'} 1 22 150 40 Insulin 20
7 151 {ts '2012-02-03 00:00:00'} 1 33 200 41 Insulin 20
8 0 {ts '2012-02-06 00:00:00'} 1 11 100 42 Insulin 20
9 101 {ts '2012-02-06 00:00:00'} 1 22 150 43 Insulin 20
10 151 {ts '2012-02-06 00:00:00'} 1 33 200 44 Insulin 20
11 201 {ts '2012-02-06 00:00:00'} 1 44 250 45 Insulin 20
CACHED false
EXECUTIONTIME 0
SQL SELECT * FROM slidingscale Where who = 20 ORDER BY datediscontinued, beginning asc
I include the dump of what is in my database.
Thanks guys