存储过程声明:
CREATE PROCEDURE countingObject
@OBJ1_count INT OUTPUT,
@OBJ2_count INT OUTPUT,
@OBJ3_count INT OUTPUT
AS
BEGIN
SELECT @OBJ1_count = (SELECT COUNT(*) FROM OBJECTS
WHERE OBJECT_NAME = 'OBJ1');
SELECT @OBJ2_count = (SELECT COUNT(*) FROM OBJECTS
WHERE OBJECT_NAME = 'OBJ2');
SELECT @OBJ3_count = (SELECT COUNT(*) FROM OBJECTS
WHERE OBJECT_NAME='OBJ3')
END;
执行完成如下
DECLARE @OBJ1_coun INT
DECLARE @OBJ2_coun INT
DECLARE @OBJ3_coun INT
EXECUTE countingObject @OBJ1_coun OUTPUT, @OBJ1_coun OUTPUT, @OBJ1_coun OUTPUT;
SELECT
@OBJ1_coun as OBJ1_Count,
@OBJ2_coun as OBJ2_Count,
@OBJ3_coun as OBJ3_Count
正在输出输出
相应的表格是
请在我做错事的地方帮助我。
提前致谢。
答案 0 :(得分:1)
调用存储过程的方式错误 - 您将所有三个计数都返回到@OBJ1_coun
....
EXECUTE countingObject @OBJ1_coun OUTPUT, @OBJ1_coun OUTPUT, @OBJ1_coun OUTPUT;
-- OK ---- ********** WRONG ***** WRONG
试试这个:
DECLARE @OBJ1_coun INT
DECLARE @OBJ2_coun INT
DECLARE @OBJ3_coun INT
EXECUTE countingObject @OBJ1_coun OUTPUT, @OBJ2_coun OUTPUT, @OBJ3_coun OUTPUT;
SELECT
@OBJ1_coun as OBJ1_Count,
@OBJ2_coun as OBJ2_Count,
@OBJ3_coun as OBJ3_Count
答案 1 :(得分:0)
您将所有输出值分配给相同的声明变量@ OBJ1_coun
尝试这个
EXECUTE countingObject @OBJ1_coun OUTPUT, @OBJ2_coun OUTPUT, @OBJ3_coun OUTPUT;