I am using the query below and am getting back four 'Gary' records. Which I understand why that's correct for the way I have it written.
But what I really need is one 'Alstrand, Gary' record with the amount and hours summed. Everything else ignored.
How can I do that?
PH.PehOrgLvl1 as Branch
, PH.PehOrgLvl2 as Dept
, GL.GLRBASEACCT AS Acct
, LTRIM(RTRIM(PR.PRGNAMELAST + '')) + ', ' + LTRIM(RTRIM(PR.PRGNAMEFIRST + '')) as DESCRIPTION
, PH.PehHourlyPayRate as Rate
, PH.PEHCURAMT as TRANSACTIONAMT
, PH.PEHCURHRS as HOURS
, PR.PRGPAYDATE as APPLYDATE
, PH.PEHCHARGEDATE as ENTRYDATE
FROM GSHQSQL4.ULTIPRO_WSI.DBO.PEARHIST PH, GSHQSQL4.ULTIPRO_WSI.DBO.PAYREG PR, GSHQSQL4.ULTIPRO_WSI.DBO.GLDEFRLS GL
WHERE PH.PEHGENNUMBER = PR.PRGGENNUMBER AND PH.PEHEARNCODE = GL.GLRCOMPONENTCODE
AND (GL.GLRBASEACCT = '5200' OR GL.GLRBASEACCT = '5204')
AND PH.PEHORGLVL1 NOT IN ('WSI180','WSI184', 'WSIW01')
--AND PR.PRGPAYDATE >= '09/01/2013' and PH.PEHCHARGEDATE < '09/30/2013'
AND PH.PEHCHARGEDATE >= '09/01/2013' and PH.PEHCHARGEDATE < '09/30/2013'
AND PH.PehOrgLvl1 = 'WSI112'
AND PH.PEHORGLVL2 = 'WSIAMS'
and LTRIM(RTRIM(PR.PRGNAMELAST + '')) + ', ' + LTRIM(RTRIM(PR.PRGNAMEFIRST + '')) like 'Alstrand, Gary'
ORDER BY DEscription ASC