首页 > 代码库 > sql 存储过程返回多个值

sql 存储过程返回多个值

ALTER PROCEDURE your_sp_name
   
AS
BEGIN
    DECLARE @a INT, @b INT, @c INT
    SELECT @a= COUNT(1) FROM table_name WHERE 条件1
    SELECT @b= COUNT(1) FROM table_name WHERE 条件2
    SELECT @c= COUNT(1) FROM table_name WHERE 条件3
    
    SELECT @a AS a, @b AS b, @c AS c
END

--执行

EXEC your_sp_name

--结果
a           b           c           
----------- ----------- -----------
1           2           3

(所影响的行数为 1 行)

sql 存储过程返回多个值