Error:Must declare the scalar variable "@SumSalary"
It showing error because you might running your SP and execute statement in same SSMS window. It will work if you run the below query in separate SSMS window and it will not show the error.
declare @SumSalary int
exec pro3 @deptid = 3, @SumSalary = @SumSalary out
OR
You just change the local Variable name as below and you can run the query in same window -
create procedure pro3(@deptid int, @SumSalary int out) as
begin
select @SumSalary = sum(e.salary)
from emp e
inner join dept d
on e.deptid = d.deptid
where d.deptid=@deptid;
end
declare @SumSalaryOutput int
exec pro3 @deptid = 3, @SumSalary = @SumSalaryOutput out