This article is a mirror article of machine translation, please click here to jump to the original article.

View: 10608|Reply: 1

[Source] SQL Server time interval priority selection

[Copy link]
Posted on 2022-4-13 18:08:53 | | | |
Requirements: According to the time filter data, the time must be greater than the start time and less than the end time, both the start and end time records may be NULL, and there may be multiple records that meet the requirements after filtering.Take the record with the highest priority, that is, the interval record that best matches the time (the start and end times are closest to the filter criteria).

First, create a Table_2 with the following statement:

Insert a few test records as follows:


Depending on the demand, the time is:2021-11-11 00:00:00.000to find the data with the highest priority, the SQL statement is as follows:

The result is shown below:







Previous:【Practice】The Bark app for iPhone message notification push
Next:Encoding URLs and parameters in JavaScript
Posted on 2022-4-14 17:09:27 |
Learn to learn.
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com