Reputation: 135
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
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
Reputation: 523
It will work for you :
delete from [tablename]
where DATEPART(month,[datecolumn]) = @inputDigit
Upvotes: 0
Reputation: 1
delete from TABLE_NAME
where DATEPART(mm,ColumnName) = @MONTH_PARAMETER
Upvotes: 0
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
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