Insert Salary for Employee on Year and Month Basis

Raj.Trivedi
Posted by Raj.Trivedi under Sql Server category on | Points: 40 | Views : 1166
Hell Team,

Over here we will check how we can insert salary for employee who are present in the database.
If the Employee is not found then we will show a Message that Employee Does not Exist
and
If Employee Exist then we will check have we paid him the salary for the particular month and Year, if already Paid then we will show the error Message of Salary Already Paid and if not paid only then we will insert the salary

create proc InsertSalaryforEmployee
(
@EmpID int,
@EmpName varchar(50),
@Year varchar(6),
@Month int,
@Salary int
)
as
begin
declare @rowcountforEmployee int;
declare @RowCountforSalaryPaid int;
declare @ErrMessage varchar(50)
set @rowcountforEmployee = (Select COUNT(EID) from tbl_Emp where EID = @EmpID)
if(@rowcountforEmployee =0)
begin
set @ErrMessage = 'No Employee Found'
end
else
begin
set @RowCountforSalaryPaid = (select COUNT(SalaryID) from tbl_Emp_Sal where SalYear =@Year and Months = @Month )
if(@RowCountforSalaryPaid = 0)
begin
insert into tbl_Emp_Sal(Emp_Id,Emp_Name,SalYear,Months,Emp_Salary)
values
(@EmpID,@EmpName,@Year,@Month,@Salary)
set @ErrMessage = 'Salary Paid Successfully'
end
else
begin
set @ErrMessage = 'Salary Already Paid for Selected Month and Year'
end
end
select @ErrMessage 'ErrMessage'
end

Comments or Responses

Login to post response