Click here to Skip to main content
14,271,130 members

Can't get required output while executing procedure

K K Shah asked:

Open original thread
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
Tags: SQL

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the The Code Project Open License (CPOL).




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100