how to use one input and one output parameter in sql server 2008

时间:2017-12-18 07:03:23

标签: sql sql-server-2008

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

1 个答案:

答案 0 :(得分:1)

Your stored procedure returns only SELECT data Since you did not assign any value to output parameter, it is NULL

You can change your stored procedure code as follows using ALTER statement

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

Now the output parameter is assigned with the count of employees in selected department I hope it helps