Forum Discussion

Bill Campbell's avatar
Bill Campbell
Copper Contributor
Mar 13, 2018
Solved

Need some help with Script

I have a requirement to pull data from a SQL database and into Excel.   It is really pretty simple, however, I am not skilled enough in writing the SQL Script to make this work. One of the colu...
  • Yan Grenier's avatar
    Yan Grenier
    Mar 15, 2018

    So I think for 1 employee (in table CPY10100 I suppose), you can have 0 or more CPY10140 lines.

     

    This case is more, you can try this, but because I don't know your schema nor your datas, you can have multiple lines for each employee if in CPY10140 table you have multiple lines for each PIncomeCode for one employee:

     

    select 
     a.PEmployeeID as 'EmployeeID',
     a.PFirstName as 'FirstName',
     a.PLastName as 'LastName',
     (rtrim(a.PFirstName) +' '+ rtrim(a.PLastName)) as 'EmployeeName',
     case a.PContractor
      when 1 then 'Contractor'
      when 0 then 'Employee'
     End as 'Status',
     a.PDepartment as 'DepartmentCode',
     b.PDescription as 'DepartmentName',
     a.PStartDate as 'StartDate',
     ratedLine.PRate as RATED,
     grpinsLine.PRate as GRPINSD
    from CPY10100 a 
     join CPY10020 b on a.PDepartment = b.PDepartment
     left join CPY10140 ratedLine on a.PEmployeeID = ratedLine.PEmployeeID and ratedLine.PIncomeCode in ('HOURLY' , 'SALARY')
     left join CPY10140 grpinsLine on a.PEmployeeID = grpinsLine.PEmployeeID and grpinsLine.PIncomeCode = 'GRPINS'
    where PInactive = 0 
    

    Regards,

     

    Yan

     

     

Resources