I am designing a report in SSRS and ran into a snag with some bad data that I want to "mask" in SQL or SSRS. My end goal is trying to calculate the correct sum for ESTTIME AND HOURS, so whether "masking" the number or re-creating my query to pull the correct data, I am all ears. My query is below for your reference.
The problem I am having is that A.ESTTIME; at times has the same amount for multiple records, but they are technical not duplicates because the L.hours column is different. What I want to do is keep one of the ESTTIME values and zero out the other two. example
of the results are below. The sum should be SUM(ESTTIME) = 1.5 AND SUM(HOURS) = 5.8
NAME COMPCODEORDERNUMSECTIONNUMESTTIMEHOURSFIRSTNAME
customer001123455511.52.0Joe Doe
customer001123455511.52.5JoeDoe
customer001123455511.51.3Joe Doe
SELECT
DISTINCT C.NAME, L.COMPCODE, O.ORDERNUM, SEC.SECTIONNUM, A.ESTTIME, L.HOURS, E.FIRSTNAME, E.LASTNAME
FROM
ORDERLN L
JOIN ORDERS O ON O.ORDERID = L.ORDERID
JOIN ORDERSEC SEC ON SEC.ORDERID = L.ORDERID AND SEC.SECTION = L.SECTION
JOIN ORDERASSMT A ON A.ORDERID = O.ORDERID AND A.SECTION = SEC.SECTION AND A.ESTTIME IS NOT NULL AND A.EMPID = L.MECHANIC
JOIN JOBCODES J ON J.JOBCODEID = A.JOBCODEID
JOIN JOBSFLTER F ON F.JOBCODEID = A.JOBCODEID AND F.JOBSFLTID = A.JOBSFLTID
JOIN EMPLOYEE E ON L.MECHANIC = E.EMPID
JOIN SHOP S ON O.SHOPID = S.SHOPID
JOIN UNITS U ON U.UNITID = O.UNITID
JOIN CUSTOMERS C ON C.CUSTID = U.CUSTID
JOIN CUSTOMERPAYGRADE P ON P.CUSTID = C.CUSTID
WHERE
L.LINETYPE = 'LABOR'
AND L.VENDORLINE = 'N'
AND L.HOURS > 0
AND L.COMPCODE = @compCode
AND L.SHOPID = @Shop
AND CHGDATE >= @Start AND CHGDATE < @End
ORDER BY
C.NAME, L.COMPCODE, O.ORDERNUM, SEC.SECTIONNUM, A.ESTTIME, L.HOURS, E.FIRSTNAME, E.LASTNAME ASC