SQL Server date comparisons based on month and year only

后端 未结 6 963
南方客
南方客 2021-02-05 06:27

I am having trouble determining the best way to compare dates in SQL based on month and year only.

We do calculations based on dates and since billing occurs on a monthl

6条回答
  •  灰色年华
    2021-02-05 07:31

    You can join on MONTH and YEAR values of those dates:

    SELECT * 
    FROM tableName 
    WHERE YEAR(@date1) = YEAR(@date2) AND MONTH(@date1) = MONTH(@date2)
    

提交回复
热议问题