Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 从特定月份的表中删除数据_Sql_Sql Server 2005 - Fatal编程技术网

Sql 从特定月份的表中删除数据

Sql 从特定月份的表中删除数据,sql,sql-server-2005,Sql,Sql Server 2005,在我的表中,有一列存储日期。我将月数作为参数传递给存储过程 我想从表中删除该月的所有条目 有没有可能……?我想这就是你的答案: delete from yourtable where month(YourDatetimeColumn) = 5 -- for example 'may' 或 注意:用输入参数替换5。这将不会考虑年份部分日期,所以如果是MY-2014或MAY-2015,所有的都将被删除。 < P>我不熟悉SQL Server版本,但您被标记为2005。 如果month() dele

在我的表中,有一列存储日期。我将月数作为参数传递给存储过程

我想从表中删除该月的所有条目


有没有可能……?

我想这就是你的答案:

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


注意:用输入参数替换
5
。这将不会考虑<代码>年份部分日期,所以如果是MY-2014或MAY-2015,所有的都将被删除。

< P>我不熟悉SQL Server版本,但您被标记为2005。 如果
month()

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

但与其他答案一样,这将删除您提供的所有字段(如您所述),不考虑年份。

这将适用于您:

delete from TABLE_NAME
where DATEPART(mm,ColumnName) = @MONTH_PARAMETER
delete from [tablename] 
where DATEPART(month,[datecolumn]) = @inputDigit

在给定的查询中,以您希望删除数据的月份的数字传递您的月份

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