A problem that has been resolved for a long time today,
The cause is
Obtain the data with the maximum time and date.
Previously, we thought that only the MSX function could solve the problem,
Select * From tablename where date = (select max (date) from tablename) and time = (select max (time) from tablename)
During the test, we found that a piece of data was taken out. Because the test was performed on two pieces of data in a day without a different date, we thought it was correct on that day. However, the data was written the next day, if you want to retrieve the data, but find that there is no data, and return NULL rows, you think it is all code and there is a problem. You haven't found the data for half a day. You have taken a closer look at the code in the stored procedure, the returned data is indeed empty.
This is a nested query statement. The statement of external query is executed first.
For example, there are three pieces of information. Use the statement written above to execute it in the SQL analyzer.
Analyze such a queryThe first query is the date, and the maximum date is the following two statements. In the comparison time. It is found that the maximum time is only one
Number of entriesSo that the second data is taken out of course. This is the test result at the time.
But then I modified the data. The next day, the test showed that the data was empty. No data.The analysis is like this.
The maximum number of days queried is. The third line. The most time is 21:12:21.
Is the second data entry.
In this way, there is no intersection with the result. It is null.
Later, I searched for textbooks and asked others. The problem is solved,The sorting method is used.
Order by DESC is sorted in descending order, which can be overlapped in different ways.
If the preceding statement is corrected as follows, the result is expected.
Select top 1 * From t_checkbill order by date DESC, time DESC
The above are your findings. Communication is necessary, or your own ideas are limited.