Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Delete data with specific date format

Author  Topic 

theKid27
Starting Member

21 Posts

Posted - 2013-03-13 : 22:24:12
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
Master Smack Fu Yak Hacker

2242 Posts

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

--
Chandu
Go to Top of Page

theKid27
Starting Member

21 Posts

Posted - 2013-03-14 : 05:20:58
thanks bandi
Go to Top of Page

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-03-14 : 06:00:21
quote:
Originally posted by theKid27

thanks bandi


Welcome

--
Chandu
Go to Top of Page
   

- Advertisement -