Get All Dates of Given Month and Year in SQL Server

后端 未结 11 1522
梦如初夏
梦如初夏 2021-02-19 11:22

I want to get all dates by declaring month and year in SQL server.

Can anyone please share easy lines of SQL code to get it.

For example:



        
11条回答
  •  不要未来只要你来
    2021-02-19 11:44

    WHERE Dates LIKE '2018-12%'
    

    In a datetime or timestamp it goes Year-Month, so this would pull everything that matches 2018 in December. You can mod this to use your variables as well.

    @month = 12;
    @year = 2018;
    @searchQuery = @year + @month + '%';
    
    WHERE Dates LIKE @searchQuery
    

提交回复
热议问题