SQL query to select dates between two dates

后端 未结 22 1379
囚心锁ツ
囚心锁ツ 2020-11-22 09:10

I have a start_date and end_date. I want to get the list of dates in between these two dates. Can anyone help me pointing the mistake in my query.<

22条回答
  •  渐次进展
    2020-11-22 09:44

    Try this:

    select Date,TotalAllowance from Calculation where EmployeeId=1
                 and [Date] between '2011/02/25' and '2011/02/27'
    

    The date values need to be typed as strings.

    To ensure future-proofing your query for SQL Server 2008 and higher, Date should be escaped because it's a reserved word in later versions.

    Bear in mind that the dates without times take midnight as their defaults, so you may not have the correct value there.

提交回复
热议问题