create procedure spGetEmployeByDepartmentIdCount
@DepartmentIdType int ,
@DepartmentIdCount int output
as
Begin
select count(id)
from tblemploye1
where @DepartmentIdType = id
End
Declare @DepartmentIdCount int
Declare @id int
set @id = 1
Execute spGetEmployeByDepartmentIdCount @id, @DepartmentIdCount output
print @DepartmentIdCount
存储过程仅返回SELECT数据由于未向输出参数指定任何值,因此它为NULL
您可以使用ALTER语句更改存储过程代码,如下所示
select
@DepartmentIdCount = count(id)
from tblemploye1
where
id = @DepartmentIdType
现在输出参数被分配了所选部门的员工数量,我希望它有所帮助