I'm selecting a record from one table(mctrxhst) which is based on a value in a 2nd table(mccrwhst)One record in the mxtrxhst can have multiple records in the mccrwhst.Example:MCTRXHSTJOB_NO CONTROL_NO LBR_HRS1234 33 8MCCRWHSTJOB_NO CONTROL_NO EMP_NO SHIFT1234 33 2 11234 33 3 1
I only want labor hours for shift 1. When I used the following code it doubles my labor hours because I have two records in the mccrwhst. How can I prevent this from happening?select mctrxhst_sql.dept, SUM(case when MONTH(mctrxhst_sql.trx_dt)=month(getdate()) and year(mctrxhst_sql.trx_dt)=YEAR(getdate()) and DAY(mctrxhst_sql.trx_dt)= DAY(getdate()) then mctrxhst_sql.lbr_hrs END) AS Yesterday from mctrxhst_sql left outer join mccrwhst_sql on mctrxhst_sql.job_no = mccrwhst_sql.job_no and mctrxhst_sql.control_no = mccrwhst_sql.control_no