Transfer the start date and end date to the stored procedure from the program, and start the Stored Procedure
Let's take a look at this function:
You will put two text boxes in the program interface to allow users to fill in the date to query data. In this case, you may think that there are three possible cases. You can fill in only the first text box, or only the second text box, or both of them.
In these three cases, how do you deal with the logic?
As Insus. NET understands, if the user only fills in the date of the first text box, and the second does not, it means that the user wants to tell the system to query records greater than or equal to this date.
If the first text box is not entered, only the second date is entered. This indicates that you want to query records that are less than or equal to this date.
If both of them are specified, it indicates that the record between the specified date is queried. The value is greater than or equal to the start date and less than or equal to the end date.
Here, if a condition of less than or equal to the end date is determined, the record may be incorrect. Because of the date passed in, when it is actually passed in to SQL, it will change to xxxx-xx 00:00:00. 000, right.
If the queried field contains time, it is inaccurate. The record has a 09:55:13 value, but the date you transferred is like. After conversion, It is 00:00:00. At this time, the record cannot be queried if it is less than or equal.
Therefore, when processing the end date, the correct condition for use isEnd Date plus one day, UseLessCondition.
In the stored procedure, you can write as follows:
After obtaining the where condition, you can proceed to the next step:
The Code in line #33 and #34 above determines that if the date of both text boxes is not filled, the query will directly query records of all dates.
In addition, dynamic SQL is used for running. I don't understand the syntax. Please refer to MSDN.