?
Solved

Trying to delete from database on datetime criteria

Posted on 2014-02-10
3
Medium Priority
?
277 Views
Last Modified: 2014-02-10
I am trying to delete all records from a table that are older than 12 months.  The date field is a datetime field.  I have the following code:

<CFSET DelDate = DateAdd("yyyy",-1,Now())>

<CFQUERY NAME="DelLogs" DATASOURCE="JobOrder#Sfx#">
  DELETE FROM JOLog
  WHERE TDate <= <CFQUERYPARAM Value="#DelDate#"  CFSQLTYPE="CF_SQL_DATETIME">
</CFQUERY>

When I run the code nothing is deleted.  What am I doing wrong?
0
Comment
Question by:jdthedj
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 52

Accepted Solution

by:
_agx_ earned 2000 total points
ID: 39848348
EDIT:
Assuming you've verified the table actually contains records older than 1 year ago...

          SELECT COUNT(*) AS TotalMatchingRecords
          FROM    JOLog
          WHERE  TDate <= <CFQUERYPARAM Value="#DelDate#"  CFSQLTYPE="CF_SQL_TIMESTAMP">

Open in new window


If you wish to include the current time, ie remove all records earlier than 2014-02-10 12:03:15 PM use:

....
WHERE TDate <= <CFQUERYPARAM Value="#DelDate#"  CFSQLTYPE="CF_SQL_TIMESTAMP">

Open in new window


To use the date only, ie remove all records earlier than 2014-02-10

....
WHERE TDate < <CFQUERYPARAM Value="#DelDate#"  CFSQLTYPE="CF_SQL_DATE">

Open in new window

0
 
LVL 3

Author Closing Comment

by:jdthedj
ID: 39848368
Thanks agx!
0
 
LVL 52

Expert Comment

by:_agx_
ID: 39848377
Welcome :)
0

Featured Post

How to Create Failover DNS Record Sets in Route 53

Route 53 has the ability to easily configure DNS record sets specifically for failover scenarios. These failover record sets can be configured to failover to full-blown deployments in other regions or to a static HTML page that informs your customers of the issue.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article  is about submitting  form through  ColdFusion.Ajax.submitForm to the action page and send a response back in JSON format which later can be decoded using ColdFusion.JSON.decode. By this way you can avoid the usual page refresh for subm…
PROBLEM:  How to open a cfwindow or run a function on double click of a cfgrid row. One of my clients wanted to be able to double click on a row item to get more detailed information about a transaction and to be able to modify the line items i…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question