A faster statement for time queries in SQL Server

Source: Internet
Author: User
Tags comparison count getdate
server| Comparison | The comparison of the statements in access is simple, such as the SELECT * from table Where thetime># ' & Now () & #这样即可

This cannot be done in MSSQL, and is compared using the DateDiff statement and the GETDATE () function.

For example, select Count (*) from table where DateDiff (S,getdate (), thetime) >0, I specifically made a 500,000-piece table of data, which would take almost 1200 milliseconds to execute.

Later studied, found that in fact, do not need to use the DateDiff function, you can directly use the > to compare, the statement is as follows: Select Count (*) from table Where thetime>getdate (), so almost 750 milliseconds, Nearly 500 milliseconds faster.



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.