Microsoft SQL Server
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMicrosoft SQL Server

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old September 2nd, 2003, 09:35 PM
rajkumar rajkumar is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: Singapore
Posts: 6 rajkumar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Lightbulb Housekeep table - Very Urgent

Hi All,

I need to do housekeep in a table based on the following condition

Condition: If the first record is before 2 yrs, then the cascading records whether 2 yrs or created yesterday should get deleted. I created a module for this, pls correct me if myself done any wrong.

Dim tempdate As Date
Dim curdate As Date
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim tbl As DAO.Recordset
curdate = Date
db = CurrentDb()
tempdate = DateAdd("YYYY", -2, curdate)
rst = db.OpenRecordset("select nric from offender where [date recorded] = '#tempdate#'")
Do While rst.EOF = False
tbl = db.OpenRecordset("select * from offender where nric = rst(0)")
tbl.Delete
rst.MoveNext
Loop


Thanks in advance

Raj

Last edited by rajkumar : September 3rd, 2003 at 01:52 AM.

Reply With Quote
  #2  
Old September 3rd, 2003, 01:37 PM
rdoekes rdoekes is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Location: Strasbourg, France
Posts: 181 rdoekes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 20 sec
Reputation Power: 7
Send a message via AIM to rdoekes Send a message via Yahoo to rdoekes
You can use an action query to execute the delete in one swoop:

Code:
Dim tempdate As Date 
Dim curdate As Date 
Dim db As DAO.Database 

curdate = Date 
db = CurrentDb() 
tempdate = DateAdd("YYYY", -2, curdate) 
db.Execute ("DELETE FROM offender WHERE " & _
" [date recorded] = '#tempdate#'") 

In this case you do not need to create 2 recordsets which uses a lot of overhead.

Hope this helps
__________________
- Rogier Doekes

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMicrosoft SQL Server > Housekeep table - Very Urgent


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 3 hosted by Hostway