SunQuest
           ColdFusion Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreColdFusion Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old July 23rd, 2004, 01:18 PM
mkm mkm is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 104 mkm User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 h 51 m 53 sec
Reputation Power: 5
problem with searching by date range

Hello,

I have a form that allows a user to search by job number, date range, or query string. The job number and query string work just fine but the date range returns no results.

Here is the code I have on my query results page:

-----------------------------------------------------------------
<cfquery name="q_queryResults" datasource="PLOG">
SELECT *
FROM data_admin.Main_log
WHERE del_job = 0
AND 0=0

<CFIF #FORM.Job_Number# IS NOT "">
AND Job_Number LIKE ('%#trim(FORM.Job_Number)#%')
</CFIF>

<CFIF #FORM.startDate# IS NOT "">
AND Date_Completed BETWEEN #CreateODBCDate(form.startDate)# AND #CreateODBCDate(form.endDate)#
</CFIF>

<CFIF #FORM.querystring1# IS NOT "">
AND Refuge_Literal LIKE ('%#trim(FORM.querystring1)#%') OR Requestor LIKE ('%#trim(FORM.querystring1)#%') OR Requestor_Office LIKE ('%#trim(FORM.querystring1)#%') OR Project_Type LIKE ('%#trim(FORM.querystring1)#%') OR Map_Type LIKE ('%#trim(FORM.querystring1)#%') OR Rq_Description LIKE ('%#trim(FORM.querystring1)#%') OR Assigned_To LIKE ('%#trim(FORM.querystring1)#%')
</CFIF>

<CFIF #FORM.querystring2# IS NOT "">
#FORM.querytype# Refuge_Literal LIKE ('%#trim(FORM.querystring2)#%') OR Requestor LIKE ('%#trim(FORM.querystring2)#%') OR Requestor_Office LIKE ('%#trim(FORM.querystring2)#%') OR Project_Type LIKE ('%#trim(FORM.querystring2)#%') OR Map_Type LIKE ('%#trim(FORM.querystring2)#%') OR Rq_Description LIKE ('%#trim(FORM.querystring2)#%') OR Assigned_To LIKE ('%#trim(FORM.querystring2)#%')
</CFIF>

ORDER BY Date_Assigned DESC, Job_Number DESC

</cfquery>
-----------------------------------------------------------------

I'm thinking maybe it's some kind of syntax or format problem?

Thanks for any help,
Melissa

Reply With Quote
  #2  
Old July 23rd, 2004, 02:44 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,611 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 9 h 10 m 21 sec
Reputation Power: 53
It looks ok to me...are you getting an error or just getting no results? Can you look at the SQL and verify that it is running the correct part of the WHERE clause? And also verify that there are records that meet ALL of the criteria in the database?
__________________
Ask if you have a question, but also help answer questions that you have knowledge of! Thanks, Brian.
How to Post a Question in the Forums

Reply With Quote
  #3  
Old July 23rd, 2004, 03:03 PM
mkm mkm is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 104 mkm User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 h 51 m 53 sec
Reputation Power: 5
Hi kiteless,

No errors are returned, just no data either. Using any of the other search terms (job#, query strings) work great, just the date range is the problem. The data type for the date_completed field is smalldatetime if that makes any difference (why I used CreateODBCDate). As for meeting criteria I think it should work. If I enter only a date range and nothing else then it should return all records between the dates specified and it returns nothing. If I combine a date range with a query string then it ignores the date range so it seems it isn't reading it at all?

thanks,
melissa

Reply With Quote
  #4  
Old July 23rd, 2004, 04:06 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,611 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 9 h 10 m 21 sec
Reputation Power: 53
Can you look at the SQL statement that is running and verify that it looks correct? If you take that SQL and paste it into your database SQL editor, does it run?

Reply With Quote
  #5  
Old July 26th, 2004, 09:12 AM
mkm mkm is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 104 mkm User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 h 51 m 53 sec
Reputation Power: 5
Sorry if this is a dumb question but isn't the SQL statement what I've posted above? That is the only SQL code I have on the page.



Melissa

Reply With Quote
  #6  
Old July 26th, 2004, 11:52 AM
mkm mkm is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 104 mkm User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 h 51 m 53 sec
Reputation Power: 5
Someone on the Macromedia forums suggested I change the if statement to read something like this:
-------------------------
<CFIF IsDate(#FORM.startDate#) AND IsDate(#FORM.endDate#)>
AND (Date_Completed >= '#CreateODBCDateTime(FORM.startDate)#' AND Date_Completed <= '#CreateODBCDateTime(FORM.endDate)#' )
<CFELSEIF IsDate(#FORM.startDate#)>
AND (Date_Completed >= '#CreateODBCDateTime(FORM.startDate)#' )
<CFELSEIF IsDate(#FORM.endDate#)>
AND (Date_Completed <= '#CreateODBCDateTime(FORM.endDate)#' )
</CFIF>
--------------------------
but now when I test it with, for example, start date of 02/10/2001 and end date 06/30/2004 I get an error message of

Error Executing Database Query.
[Macromedia][SQLServer JDBC Driver][SQLServer]Line 9: Incorrect syntax near '2001'.

Thanks for any suggestions!
Melissa

Reply With Quote
  #7  
Old July 26th, 2004, 01:14 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,611 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 9 h 10 m 21 sec
Reputation Power: 53
No, I mean the actual SQL code that is sent to the database, after CF has evaluated everything. You can see this in the debugging output. Or you can copy the cfquery, wrap it in a <cfsavecontent> block which captures the output between the tags as a variable. Then you should be able to output the variable to see the actual SQL statement.

Reply With Quote
  #8  
Old July 26th, 2004, 02:46 PM
mkm mkm is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 104 mkm User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 h 51 m 53 sec
Reputation Power: 5
Oh duh, right. Thanks for the tip - we figured it out! Problem was that instead of '0' the del_job field was defaulting to NULL so it was returning no records because the SQL statement wasn't satisfied.

Thanks again!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreColdFusion Development > problem with searching by date range


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway