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.