Notes for using select in the stored procedure!

Source: Internet
Author: User

I often write a stored procedure and use select to return a dataset. Today, in the stored procedure, I need to judge that the value of a field cannot be repeated in a table. This field is not a primary key, I used select to query,

Then, use @ rowcount to determine whether the value is equal to 0. If yes, use it directly.

Select '2' as flag

The return result always returns two select data sets, one of which is the one from the preceding query, which is then used for testing at various locations. It suddenly comes to mind that this is a mechanism of the SQL database, when you use select to query data in the stored procedure, all data will be returned, unless you assign the data queried after select to a variable, such:

Select @ flag = name from **

In this way, the stored procedure will not be called as the return set. Finally, I used a opportunistic solution:

Update SysRole set RoleName = @ RoleName where RoleName = @ RoleName

If @ rowcount = 0

//// // Implementation

Else

//// // Implementation

 

@ RoleName this parameter is the variable that is included in the stored procedure. In this way, the first select statement is solved.

 

Well, I have never paid attention to this problem.

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.