SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Delete data with specific date format
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

theKid27
Starting Member

20 Posts

Posted - 03/13/2013 :  22:24:12  Show Profile  Reply with Quote
Hi Experts/Members,

I have a table - [Removed] which data as below:

DltDate
Jan-11
Feb-11
Mar-13

I want to delete the data when the condition is not meet as below:

Delete from Removed where [DltDate] <=DateAdd(Year,-1,getdate())

but it gives me errors.
Conversion failed when converting date and/or time from character string.


Then i tried to convert the getdate to this format e.g.[Feb-2013]

SELECT REPLACE(RIGHT(CONVERT(VARCHAR(11), GETDATE(), 106), 8), ' ', '-')


DELETE FROM Removed
WHERE [DltDate] <= DATEADD(year,-1,(SELECT REPLACE(RIGHT(CONVERT(VARCHAR(11), GETDATE(), 106), 8), ' ', '-')) )

But when i combine it it still give me this error
Conversion failed when converting date and/or time from character string.

Kindly hope that you all can provide some advice on this.

Thank you.


bandi
Flowing Fount of Yak Knowledge

India
2170 Posts

Posted - 03/14/2013 :  03:25:37  Show Profile  Reply with Quote
DELETE FROM Removed
WHERE convert(datetime,'01-' + DltDate,120) <= DATEADD( Year, -1, getdate())

--
Chandu
Go to Top of Page

theKid27
Starting Member

20 Posts

Posted - 03/14/2013 :  05:20:58  Show Profile  Reply with Quote
thanks bandi
Go to Top of Page

bandi
Flowing Fount of Yak Knowledge

India
2170 Posts

Posted - 03/14/2013 :  06:00:21  Show Profile  Reply with Quote
quote:
Originally posted by theKid27

thanks bandi


Welcome

--
Chandu
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000