Click here to Skip to main content
15,881,833 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When i execute the procedure what i get the output is like -

EmployeeCode  Additions      Deductions   AdditionsAmount  DeductionsAmount
M1010         ALLOWANCE                     960.00               0
M1010         BASIC SALARY                  1390.00              0
M1010         OT1                           171.35               0
M1010                        OTHERS-DED     0.00                 1800.00


Required Output -

EmployeeCode  Additions      Deductions   AdditionsAmount  DeductionsAmount
M1010         ALLOWANCE      OTHERS-DED     960.00               1800.00
M1010         BASIC SALARY                  1390.00              0
M1010         OT1                           171.35               0


Any help would be appreciated.

What I have tried:

ALTER PROC [dbo].[PROC_EMPLOYEE_PAY_SLIP]                          
@EmplopyeeCode varchar(100),
@MonthName varchar(50),
@Year Float                             
As                                                
Begin                                            
 SELECT ISNULL(HR_EmployeeMaster.em_EmplopyeeCode,'') As EmplopyeeCode,
  ISNULL(CASE WHEN fa_ComponentMaster.Cm_ADTag = 'A' THEN fa_ComponentMaster.Cm_Name ELSE '' END,'') As Additions,
  ISNULL(CASE WHEN fa_ComponentMaster.Cm_ADTag = 'D' THEN fa_ComponentMaster.Cm_Name ELSE '' END,'') As Deductions,
  ISNULL(CASE WHEN fa_ComponentMaster.Cm_ADTag = 'A' THEN Fa_MonthSalary.Ms_Amount ELSE 0 END,0) As AdditionsAmount,
  ISNULL(CASE WHEN fa_ComponentMaster.Cm_ADTag = 'D' THEN Fa_MonthSalary.Ms_Amount ELSE 0 END,0) As DeductionsAmount
   FROM HR_EmployeeMaster                                             
    LEFT JOIN Fa_MonthSalary ON Fa_MonthSalary.ms_EmpCode = @EmplopyeeCode                                                    
    LEFT JOIN Fa_MonthDetails ON Fa_MonthDetails.mo_id = Fa_MonthSalary.Ms_MonCode                                                  
    LEFT JOIN fa_ComponentMaster ON fa_ComponentMaster.cm_code = Fa_MonthSalary.Ms_CompCode                   
  WHERE HR_EmployeeMaster.em_EmplopyeeCode = @EmplopyeeCode AND
		(SELECT CONVERT(CHAR(3), Fa_MonthDetails.mo_name)) = @MonthName AND
		Fa_MonthDetails.mon_year = @Year  
End
Posted
Updated 14-Feb-19 12:15pm
Comments
MadMyche 14-Feb-19 7:33am    
What does the actual table contain? What are the business rules?
Santosh kumar Pithani 14-Feb-19 8:00am    
Do group by on your query.In your query "ISNULL( case condition,'') " is using its means each and every records will fetch but "fa_ComponentMaster.Cm_ADTag" Column is splitting to 4 columns so unable to get what you expected.
K K Shah 14-Feb-19 8:06am    
group by what ? .. i tried but its giving error
Santosh kumar Pithani 14-Feb-19 8:31am    
Show me error message.

1 solution

When Deductions = "OTHERS-DED", then set Additions (column) to "ALLOWANCE" and group on EmployeeCode and Additions.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900