Transfer the start date and end date to the stored procedure from the program, and start the Stored Procedure

Source: Internet
Author: User

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.

 

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.