如何在sql server 2008中使用一个输入和一个输出参数

问题描述 投票:1回答:1
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
sql sql-server-2008
1个回答
1
投票

存储过程仅返回SELECT数据由于未向输出参数指定任何值,因此它为NULL

您可以使用ALTER语句更改存储过程代码,如下所示

select
    @DepartmentIdCount = count(id)
from tblemploye1 
where
    id = @DepartmentIdType

现在输出参数被分配了所选部门的员工数量,我希望它有所帮助

© www.soinside.com 2019 - 2024. All rights reserved.