Delete Records Older Than 5 Days .

Aug 20, 2002

Hello ,

I am little confused in writing the exact query i.e filling the correct details in the query .
To simplify let me explain....

I am using the query as

delete MYTABLE
where datediff(dd,loaddate,getdate())>5

I have a table now with loadate column which gets the default date and time . The loadate shows correct date and time when the data was imported in the table .

Now suppose if i want to delete previous 5 days records from today
( for e.g today is 20/08/2002 3:40:00 PM ) ideally it should delete all records which are 5 days older from today . i.e from 20/08/2002 3:40:00 PM to 15/08/2002 3:40:00 PM )
But when i execute the datediff command , it deletes the records previous than 15/08/2002 till 15/08/2002.
The records from 15/08/2002 to 20/08/2002 remain intact .

I am getting some different results .

Am i missing something in the query or i am confused about the calculation of the dates the datediff command performs .

Is the logic correct or i am missing someting important ?

Thanks and Regards
Admin001

View 1 Replies


ADVERTISEMENT

Delete Records In A Table Older Than 90 Days . Help

Aug 5, 2002

Hi ,

I have a scheduled job which does an text file import in my database . The data gets appended in my table every day from this import job .

Since my table is growing every day , i want to truncate the table after the data has been collected for three months i.e 90 days . The table will be empty and the new data will flow in through the import .

Any thoughts how to do it through query and schedule it ???

Thanks

View 1 Replies View Related

How To Delete Data Older Than X Days, Without Considering Time

Nov 11, 2005

When running the following SQL statements, I get the same results.Though I need to count only -30 days. Both statements below alsoconsider the time of the day as well, which is not desiredDELETE FROM MNT_RWHERE MNT_R.TIMESTAMP < GETDATE()- 30DELETE FROM MNT_RWHERE MNT_R.TIMESTAMP < DATEADD(d, -30, GETDATE())Here is the format of the values in columnMNT_R.TIMESTAMP2005-08-09 06:06:44.5772005-08-09 06:06:46.8102005-08-09 06:06:49.060So, since data are inserted into the MNT_R table every few seconds, mydelete statement will delete different number of rows, according to thetime of the day it runs.Can you please post a SQL query that will not give me this headache?thanx a lot all

View 2 Replies View Related

Delete Files Older Than 3 Days Using SSIS Tasks

Aug 11, 2006

I want to delete all files in a given folder that are older than 3 days from today's date.

I tried using a "Foreach Loop container" with a "File System" task inside it but found I couldn't access any file properties such as the file creation date. Am I using the wrong task for this job?



TIA,



Barkingdog



P.S. History of the problem:

I used the sql 2005 Database maintenance program to setup our database backup jobs. One day I noticed that the free space on the drive where we keep the dumps had grown small. I found that we had at least 4 weeks of dumps in there, not the 3 days I wanted to keep! I looked but could not find the "delete file" option in the SSIS package generated by the Database Maintenance Wizard. No wonder the files were piling up.

View 14 Replies View Related

SQL Server 2008 :: Delete Folders / Sub Folders Older Than N No Of Days

Jul 30, 2015

If I run the below command, it clean up the files inside the folders but unable to clean up the folder and sub-folders older than 30 days. xp_ cmd shell ' forfiles -p "D:abcd" -s -m *.* -d -30 -c "cmd /c del /Q @path"'

View 4 Replies View Related

Deleting Backup Files Older Than 2 Days

Jun 23, 2008

Friends -
I am looking for a windows script (bat file) to delete backup files which are older than 2 days.

Please provide scripts on this.

Appreciate your support

Cheers :)
Satish

View 2 Replies View Related

Deleting Backup Files Older Than 5 Days Old.

Mar 14, 2007

I am using the backup task and backing up a database but want to delete all backup files older than 5 days old. I am using the file task for this and have built the path in a variable but am trying to use a wildcard for the time. I am getting illegal character in path. How can I go about this.

I currently have E:MSSQL.1MSSQLBackupdatabasename_backup_20070309*.bak in my input variable and am trying to delete the file databasename_backup_200703091532.bak

View 4 Replies View Related

DB Engine :: How To Remove Log File Older Than X Days

Apr 20, 2015

Log file rotation and cleanup script and how to remove the log file older then x days.

View 7 Replies View Related

T-SQL (SS2K8) :: Query To Find Older Date That Is Less Than 90 Business Days

Feb 12, 2015

select DateAdd(dd,-90,getdate())

It gives the 90 days older date but i want to exclude the weekdays and holidays (saturday ,sunday,holiday)

As we dont have permission to call a function or Sp in high level environments looking for a simple query .

View 1 Replies View Related

Delete Backup Files Older Then...

Mar 5, 2007

Ok in SQL 2000 this is within the maintaince plan, where as i have to create a seprate one for sql 2005 being i assume the 'clean up history' I choose the backup andrestore option choose 2 weeks and then run the job once created it runs sucssessfully but yet it dosnt delete a thing. I have backups going back almost 2 months now.
What on earth am i not doing?

Thanks in advanced

View 6 Replies View Related

SQL Server - Select Records Added Today, Last 3 Days, 7 Days...

Oct 25, 2006

Hello,I am writing a query to select records added to a table today, in the last 3 days, in the last 7 days, and so on.Here is what I have (which seems that its not working exactly).   -- total listed today
SELECT COUNT (*) FROM mytable WHERE DATEDIFF(Day, mydatecolumn, getdate() ) <= 0-- total listed yesterday
SELECT COUNT (*) FROM mytable WHERE DATEDIFF(Day, mydatecolumn, getdate() ) <= 1-- total listed in the last 3 days
SELECT COUNT (*) FROM mytable WHERE DATEDIFF(Day, mydatecolumn, getdate() ) <= 3I'd like to be able to select the count for records added within the last X number of days. Can someone please help me out?  Thanks so much in advance.

View 1 Replies View Related

SQL Server 2012 :: Delete XML Data Older Than 2 Months

Aug 18, 2015

I have a table which has XML data, so it takes lot of time to delete it.

Here's the condition:

Archive all data older than 2 months and delete it.

What would be the good approach for this?

View 3 Replies View Related

Transact SQL :: All Records Older Than 5 Mondays Span

Oct 19, 2015

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO

[code]....

I am trying to display all records older then 5 Mondays span..so far I got this and it is working fine but it is excluding the records with Id 2 and 4 (Sundays) I would like to include these records as well.

View 4 Replies View Related

SQL Server 2008 :: Query To Delete All Backup Files Older Than A Specific Date?

Jul 29, 2015

I want to delete all backup files from a folder older than a specific date. But if I use the beklow query, I need to pass how many days of older backup files I need to delete whereas in my case, I dont know how many days/month/syears of old backup files are there in the backup folder.

EXEC xp_cmdshell 'FORFILES /p c:BACKUP /s /m *.sql /d -30 /c "CMD /C del /Q /F @FILE"'

View 2 Replies View Related

Maintenance Plan Fails Trying To Delete Files Older Thean One Day. Running SQL Server 2005

Oct 1, 2007

I get the following message when I execute a mantenance plan to delete files older than 1 day.

Error # -1073548784

Executing the query "EXECUTE master.dbo.xp_delete_file 0,N'',N'',N'2007-09-30T07:56:09'
" failed with the following error: "Error executing extended stored procedure: Invalid Parameter". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.

Any help would be appreciated!!

View 3 Replies View Related

SQL 2012 :: Delete DB After X Days

Jan 23, 2015

I am creating a Scheduled JOb that will delete backups older than 3 days old, however I seem to be missing something in my script.

DECLARE @DeleteDate datetime
SET @DeleteDate = DateAdd(day, -3, GetDate())

EXECUTE master.dbo.xp_delete_file 0,N'E:BackUps',N'bak',N' + @DeleteDate + ''

View 5 Replies View Related

Delete 2 Days Old Files - Xp_cmdshell

Apr 18, 2008

Folks:

I want to delete files on windows from a directory which are 2 days old. I understand we can do that using xp_cmdshell. Anybody with a script would really help me.


Thanks !

View 1 Replies View Related

Master Data Services :: Hard Delete All Soft Delete Records (members) In Database

May 19, 2012

I am using Master Data Service for couple of months now. I can load, update, merge and soft delete data in MDS. Occasionally we even have to hard delete data from MDS. If we keep on soft deleting records in a MDS table eventually there will be huge number of soft deleted records. Is there an easy way to hard delete all the soft deleted records from all MDS tables in a specific Model.

View 18 Replies View Related

Records That Are 90 Days Old

Feb 3, 2006

How can I select records from a schedule table that have end dates older than 90 days?

Can I do getdate() -90?


Code:

select *
from dbo.schedule
where enddate <> endate-(90 days?)

View 1 Replies View Related

Get All Records From Last Two Days?

Apr 18, 2006

Hi Everyone,I use the following to get records from the last two days in MySql:where date_entered <= curdate() and date_entered >=DATE_SUB(curdate(),INTERVAL 2 day)I'm looking to do the same in MS-Sql server but I'm just not getting it.I've got this so far which does not work:where hit_date <= GETDATE() and hit_date >= DATE_SUB(GETDATE(),INTERVAL 2day)then I tried this:WHERE hit_date >= DATEDIFF(GETDATE(), (GETDATE()-2)>Essentially, I need all records from the last two days.Any help or guidance in this matter would be greatly appreciated.-JohnyB

View 5 Replies View Related

Data Flow Task To Delete Records And Then Insert Records In Transaction

Aug 6, 2007

HI,

I have been trying to solve the locking problem from past couple of days. Please help mee!!

Scenario:
--------------
I have a SSIS package in which 2 data flow tasks. 1st data flow task deletes records from a 5 tables and the 2nd data flow task should insert records into 1 of the five tables after the success of 1st data flow task. This scenario runs in Transacation.

The above scenrio in the 2nd data flow task hangs in runtime. It does not complete. with sp_who2 command i could see that there is an intent share lock(LK_M_IS) on the table and the status is SUSPENDED.

I dont know how to come out of this locking. Please help.

Thanks ,
Sunil

View 7 Replies View Related

SQL Server - Get Records From The Last X Days

Oct 25, 2006

Hello,I am writing a SQL query to count records in a table from the last "X" number of days.There is a dateTime column that I want to base this off of:Lets say..  I want to count the records that were added in the last 3 days.  What is the query I should use to get this value?Here is what I have and it seems to not be working correctly:SELECT @TotalListedLast3Days = COUNT (*) FROM myTable WHERE DATEDIFF(Day, DateAdded, getdate() ) <= 3Can someone help so I am able to get the count of records added in the last "X" days?Thank you very much.

View 2 Replies View Related

Records Greater Than 30 Days

Sep 10, 2014

I have a query pulling all records with a disconnect date and a transaction date. However, I would like to retrieve any records that have a transaction date greater than 30 days from the disconnect date. I have been unable to figure out the correct formula to use. I think I need to use the datediff function in SQL, but I've never really used this function before.

View 2 Replies View Related

Select Records From Past 30 Days

Jul 21, 2004

What would my statement look like if I have a column in a table (SoftwareInstall) called InstalledOn which stores a date in shortDateString format and I want to select all the records where that date is <= 30 days previous to today's date. Any ideas?

View 1 Replies View Related

Job To Truncate Database Records More Than 15 Days Old

Jan 26, 2005

I have a SQL Server 2K db with some 10 tables and I want to setup a nightly job to truncate all db records which are more than 15 days old. Can anyone provide me with steps involved? Any help will be highly appreciated.

View 3 Replies View Related

Find Records For X Previous Days

Jul 13, 2005

On a webform, I have three button ... [7 days]  [15 days]  [30 days]When the user clicks one of the buttons, I want to return their orders for the past X days. The WHERE clause would include something like this (for 7 days):WHERE (Order_Date BETWEEN CONVERT(DATETIME, GETDATE() - 7, 102) AND CONVERT(DATETIME, GETDATE(), 102))How do I parameterize the number of days?Thanks,Tim

View 2 Replies View Related

Returning Records Within Days Range

Oct 31, 2013

This is a follow on from one of my earlier threads where I was trying to return one specific record. In this case I am trying to return multiple records for the same person ID and within a number of days range. Snapshot of my date with same PersonID:

PersonID Arrival_Date Leaving_Date ArrivalID
======== ============ ============ =========
123456 01/12/2012 01/12/2013 arr_56464
123456 10/12/2012 10/12/2013 arr_56474
123456 13/12/2012 13/12/2013 arr_56494

And from this I want to check if one record's leaving date of the record is within 7 days of another record's arrival date. I also want to return the record that had a leaving date within 7 days of the next arrival date.I understand that if I self join on personID with the data above I will get 9 rows, for each row I will get 3 matches, I am using INNER JOIN to join to the same table but with a different alias so I assume this is the self join I should be using.

But then how do I process this? I would want to say for record 1 check the leaving date is within 7 days of arrival date of any other record matching that PersonId but not ArrivalID, and return both records.From my snapahot of code I would eventually want to return:

PersonID Arrival_Date Leaving_Date ArrivalID
======== ============ ============ =========
123456 10/12/2012 10/12/2013 arr_56474
123456 13/12/2012 13/12/2013 arr_56494

But can't seem to get this using a self join query like this:

select a.PersonID, a.Leaving_date,a.Arrival_Date,a.arrivalID
from arrivals a INNER JOIN arrivals b
ON b.personID = a.personID
WHERE
a.arrivalid != b.arrivalid
and DATEDIFF(DD, b.[Leaving_date], a.[Arrival_Date]) <=7
and DATEDIFF(DD, b.[Leaving_date], a.[Arrival_Date]) >=0

View 4 Replies View Related

Sql Query To Return Records That Are Only 45 Days

Dec 1, 2007

The topic pretty much sums up my question.

What would the sql query be to return only all the records in a table that are 45 days old from today.

Thank you for any help in this matter

Al

View 5 Replies View Related

Getting Records That 7 Days Pass Today's Date

Feb 26, 2008

I want to get all records that are 7 days pass today's date and not equal to today's date.  Don't know how to write it so I can get records 7 days old but with this procedure I'm still getting records that are due today.  Hope this makes sense.  Can someone assist me.
select * from libraryrequestwhere  duedate > getdate() and duedate != getdate()

View 5 Replies View Related

Calculate Median Of Difference In Days Between Records

Jan 24, 2006

I have a table of sample data

Samples(sample_no, sample_date..)

I have no idea how to do the following in sql server or if its even possible:

1. Calculate the difference in days between all samples.
2. Select the median result

Any trick to get this done would be really helpful

thanks,

DB

View 3 Replies View Related

Calculate Median Of Difference In Days Between Records

Jan 24, 2006

I have a table of sample data

Samples(sample_no, sample_date..)

I have no idea how to do the following in sql server or if its even possible:

1. Calculate the difference in days between all samples.
2. Select the median result

Any trick to get this done would be really helpful

thanks,

DB

View 10 Replies View Related

Get Count Of Records Grouped By Days And User

Dec 24, 2013

If I have a table like this:

ID User Date
20 22 1-1-2013
21 22 1-1-2013
22 31 1-1-2013
23 22 1-1-2013
24 22 1-2-2013
25 22 1-2-2013
etc...

How can I get the count of records grouped by date and user?

Date 22 31
1-1-2013 3 1
1-2-2013 2 0
etc...

Is this possible?

View 4 Replies View Related

Transact SQL :: Split Records If Total Days Greater To 1

Nov 5, 2015

I want to split the data every employeid wise based on fromdate and todate if totaldays>1.

sample output specified below ....but same output required for allthe empid's

create table attendence(EmployeeID nvarchar(20),[From] datetime,[To] datetime,TotalDays float)
insert into attendence values('1417','2015-11-02 22:48:49.450','2015-11-04 22:48:49.450',3)
insert into attendence values('1418','2015-11-04 22:48:49.450','2015-11-04 22:48:49.450',1)
insert into attendence values('1419','2015-11-03 22:48:49.450','2015-11-04 22:48:49.450',2)
insert into attendence values('1420','2015-11-04 22:48:49.450','2015-11-05 22:48:49.450',2)
insert into attendence values('1421','2015-11-01 22:48:49.450','2015-11-04 22:48:49.450',4)

 OP
 -------------------------
 EmployeeID    [From]                          [To]                              TotalDays
 1417          2015-11-02 22:48:49.450         2015-11-02 22:48:49.450             3
 1417          2015-11-03 22:48:49.450         2015-11-03 22:48:49.450             3
 1417         2015-11-04 22:48:49.450          2015-11-04 22:48:49.450             3

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved