Atul Dislay
Atul Dislay

Reputation: 135

Delete Data From Table of Specific Month

In My Table, I Have a Column Which Stores the Date. I am Passing Month Number as an argument to a stored Procedure.

I would like to delete all entries of that month from table.

Is it Possible....??

Upvotes: 3

Views: 8522

Answers (5)

Chiragkumar Thakar
Chiragkumar Thakar

Reputation: 3716

Here in given Query pass your month in Digit of which month you want to delete the data.

Delete from tbl_xyz where DATEPART(mm, clm_CreatedTime) = @Month

Upvotes: 0

Chetan Bodke
Chetan Bodke

Reputation: 523

It will work for you :

delete from [tablename] 
where DATEPART(month,[datecolumn]) = @inputDigit

Upvotes: 0

Naresh Sharma
Naresh Sharma

Reputation: 1

delete from TABLE_NAME
where DATEPART(mm,ColumnName) = @MONTH_PARAMETER

Upvotes: 0

Raybarg
Raybarg

Reputation: 720

I am not familiar with SQL server versions, but youre tagged as 2005.

If there is issues with month() then you can also use;

delete from your_table where datepart(month, table_datefield) = @procedure_argument_month

But as in other answer, this will delete all fields which month is as you provided, as you described, not minding the year.

Upvotes: 2

Deep
Deep

Reputation: 3202

I think this is your answer :

delete from yourtable where month(YourDatetimeColumn) = 5 -- for example 'may'

OR

delete from yourtable where datepart(mm,YourDatetimeColumn) = 5 -- for example 'may'

Note : replace 5 with your input parameter. This will not consider the year part of your date so if it is may-2014 or may-2015, all will be deleted.

Upvotes: 5

Related Questions