This code runs but the results gives multiple categories and I want just the latest one.
SELECT DISTINCT [vtePayrollBase].[PrbEmpName] AS [Name],
[vtePayrollBase].[PrbBirthDate] AS [DOB],
[vtePayrollBase].[PrbDateLastHire] AS [Last Hire Date],
[vtePayrollBase].[PrbEmpSSN] AS [SSN],
MAX(veEmploy.[eeDateEnd]) AS [Term Date],
MAX(veEmploy.[eeCategory]) AS [Employee Type],
MAX(vtCheckSumm.[CsuPayPeriod]) AS [Pay Period],
vtEPayrollBase.[PrbPayDiv]
+ vtEPayrollBase.[PrbPayDept] AS [Dept],
Substring(RIGHT(Rtrim([CsuEmpNumber]),10),7,4) AS [Emp No],
SUM(vtCheckSummHE.[CseYTDHrs]) AS [YTD Hours],
MAX(vtCheckSumm.[CsuYTDGrossPay]) AS [YTD Gross Pay]
FROM vtCheckSumm
INNER JOIN vtEPayrollBase
ON vtEPayrollBase.[prbFlxIDeb] = vtCheckSumm.[CsuFlxIDEb]
AND vtEPayrollBase.[prbDateEnd] IS NULL
INNER JOIN vtCheckSummHE
ON vtCheckSumm.[CsuFlxID] = vtCheckSummHE.[CseFlxIdCsu]
INNER JOIN vEBase
ON vtCheckSumm.[CsuFlxIDEb] = vEBase.[EbFlxId]
INNER JOIN vEEmploy
ON vEBase.[EbFlxID] = vEEmploy.[EeFlxIdEb]
WHERE ((((((((((((vtCheckSumm.[CsuDateBeg] >= '#STARTDATE#'
AND vtCheckSumm.[CsuDateBeg] <= '#ENDDATE#')
AND Substring(RIGHT(Rtrim(vtEPayrollBase.[PrbPayDept]),4),
4,1) <> 3)))))))))))
GROUP BY [vtEPayrollBase].[PrbPayDiv],[CsuEmpNumber],[vtePayrollBase].[PrbEmpName],[vtePayrollBase].[PrbBirthDate],
[vtePayrollBase].[PrbEmpSSN],[vtePayrollBase].[PrbPayDept],[vtePayrollBase].[PrbDateLastHire]
I'd like to incorporate even one other table from above into this code...
SELECT b.[EeFlxID] AS [MaxID],
b.[EeCategory],
b.[EeSocNumber]
FROM vEEmploy b
JOIN (SELECT a.[EeSocNumber], MAX(EeFlxID) MaxEeFlxID
FROM vEEmploy a
GROUP BY [EeSocNumber]) a
ON a.[MaxEeFlxID] = b.[EeFlxID])
|