select * from ( select case when x.POPRCTNM is null then p.POPRCTNM else p.POPRCTNM end as RCT_Num, PONUMBER PO, p.VENDORID Supplier, ITEMNMBR Item, QTYSHPPD shipped, UOFM Type, TRXLOCTN Location, case when CONVERT(DATE, x.receiptdate) is null then convert(date, p.DATERECD) else CONVERT(DATE, x.receiptdate) end as Date_Received from ALPLA.dbo.pop10500 (nolock) as p left join ALPLA.dbo.POP10300 as x on p.POPRCTNM = x.POPRCTNM WHERE TRXLOCTN LIKE '[gpCode]%' and p.POPTYPE = 1) a where Date_Received BETWEEN '[startDate]' AND '[endDate]'