Delete data from a table of a specific month

In my table, I have a column that stores the date. I am passing the month number as an argument to a stored procedure.

I would like to delete all records of this month from the table.

Is it possible to...??

+3


source to share


5 answers


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 part of year

your date, so if it could be 2014 or May 2015, all will be deleted.

+5


source


I'm not familiar with the SQL server versions, but you tagged as 2005.

If there are problems with month()

, you can also use;



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

      

But as in the other answer, this will remove all fields that are month as you specified as you described, regardless of the year.

+2


source


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

      

0


source


This will work for you:

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

      

0


source


Here, in the given query, go through the month in digit, in which month you want to delete the data.

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

      

0


source







All Articles