WHERE Clause to find all records in a specific month

后端 未结 10 2130
傲寒
傲寒 2020-12-04 10:07

I want to be able to give a stored procedure a Month and Year and have it return everything that happens in that month, how do I do this as I can\'t compare between as some

10条回答
  •  半阙折子戏
    2020-12-04 10:38

    One way would be to create a variable that represents the first of the month (ie 5/1/2009), either pass it into the proc or build it (concatenate month/1/year). Then use the DateDiff function.

    WHERE DateDiff(m,@Date,DateField) = 0
    

    This will return anything with a matching month and year.

提交回复
热议问题