WHERE Clause to find all records in a specific month

后端 未结 10 2101
傲寒
傲寒 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:28

    Can I just ask to compare based on the year and month?

    You can. Here's a simple example using the AdventureWorks sample database...

    DECLARE @Year       INT
    DECLARE @Month      INT
    
    SET @Year = 2002
    SET @Month = 6
    
    SELECT 
        [pch].* 
    FROM 
        [Production].[ProductCostHistory]   pch
    WHERE
        YEAR([pch].[ModifiedDate]) = @Year
    AND MONTH([pch].[ModifiedDate]) = @Month
    

提交回复
热议问题