WHERE (p.PartNoAlias='' OR w.PartNoAlias=p.PartNoAlias)

or if(p.PartNoAlias='',,w.PartNoAlias=p.PartNoAlias))

OR (p.PartNoAlias != '' AND w.PartNoAlias=p.PartNoAlias))

SELECT p.Warehouse, p.PartNo, COUNT(w.WONo) AS OrderCount, -- will always be 1 because w.WONo is in group by SUM(w.Qty) AS QtySold, MAX(w.EntryDate) AS LastSaleDate, WONoFROM parts pLEFT JOIN woparts w ON (w.partno IN (p.partno, p.PartNoOriginal, p.PartNoAlias, p.OldNUmber) or (p.PartNoAlias = '' AND w.PartNoAlias = '')) and p.Warehouse = left(w.BillTo,5) AND Left(w.billto, 1) = 't' and w.EntryDate > '2012-10-16' and w.WONo < 910000000WHERE Left(p.Warehouse,1) = 't' and p.OnHand > 0GROUP BY p.Warehouse, p.PartNo, w.WONo