MS SQL Server with time records how to query

Source: Internet
Author: User

Original: MS SQL Server with time records how to query

For example, a table [a] has a save date containing the Time field [b], if the paragraph [b] as the query criteria to query data records. And we have to spend some time trying to find the records we want.

Now we need to query all records for 2014-06-21 of the day:

SELECT *  from [A] WHERE [B] = ' 2014-06-21 '


The syntax above will not be queried for any records. Perhaps some netizens think of using between:

 select  *   [ a   [  b      " 2014-06-21 00:00:00  Span style= "color: #ff0000;" > '  


This specifies the date range, and you can actually query the data record for this day, but if [B] has a store for 2014-06-21 23:59:59. xxx Such time, this record will not be queried.
Perhaps you can use the following method to solve the "How to get the midnight time value of the current date" http://www.cnblogs.com/insus/archive/2011/09/09/2172419.html and "how to get the maximum time value for the current date" Http://www.cnblogs.com/insus/archive/2011/09/09/2172687.html

In this way, it can be written as:

But the implementation seems to be a bit more complicated, is it easier to spell it? Look:


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.