简体   繁体   中英

Stored procedure has multiple SELECT statements

This stored procedure has multiple SELECT statements - I need to write a condition based on one SELECT statement results among them without altering the stored procedure:

CREATE PROC Test
AS
BEGIN
    SELECT 1 AS ID 
    FROM EMPLOYEE

    SELECT NAME, ADDRESS, STATE 
    FROM EMPLOYEE --NEED TO TAKE ROW COUNT 
END

After executing the stored procedure, I'll get 2 result sets. But I need to row count of 2nd select statement, without altering the stored procedure.

Based on that rowcount, I need to work further.

exec Test 
select @@rowcount

In this case, @@rowcount will always return last result set row count.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM