SQL Server query by time period

Source: Internet
Author: User
Tags sql server query

When writing SQL statements that query by time period, we generally write the query conditions as follows:

Where date> = '2014-01-01 'and date <= '2014-10-1 '.

However, some SQL statements are converted into the following:

Where date> = '2014-01-01 0:00:00 'and date <= '2014-10-1: 0: 00: 00'. If you look at this condition again, you may understand,

That is, the data after '2017-10-1 0:00:00 'cannot be found, for example ('2017-10-1: 08: 25: 00'), that is, the data of cannot be found.

If you know the reason, you can modify the query condition:

Where date> = '2014-01-01 'and date <= '2014-10-1 23:59:59' or where date> = '2014-01-01 'and date <= '2014-10-2'.

When writing SQL statements that query by time period, we generally write the query conditions as follows:

Where date> = '2014-01-01 'and date <= '2014-10-1 '.

However, some SQL statements are converted into the following:

Where date> = '2014-01-01 0:00:00 'and date <= '2014-10-1: 0: 00: 00'. If you look at this condition again, you may understand,

That is, the data after '2017-10-1 0:00:00 'cannot be found, for example ('2017-10-1: 08: 25: 00'), that is, the data of cannot be found.

If you know the reason, you can modify the query condition:

Where date> = '2014-01-01 'and date <= '2014-10-1 23:59:59' or where date> = '2014-01-01 'and date <= '2014-10-2'.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.