I just came across this query and am not sure what's going on in this particular section of the SQL statement. I've never seen "if" statements in a SQL query. Tried googling this, but no example that I found matched what I was looking for. Here's the relevant part of the query.
select mfg.name as mfgname,ap.manufacturer_id,ap.po_id,mfg.req_facacct as ReqAcctNum,ifm.mfg_acct_num as FacNum,mfg.acctnumber,
if(fac.dtmcontract = 1 and ap.pay_facility = 0 and ap.facility_orders <> 'FacReorder','M',
if(fac.dtmcontract = 1 and ap.pay_facility = 0 and ap.facility_orders = 'FacReorder' and ap.inventorytype = 'Rep Delivery','M',
if(fac.dtmcontract = 0 and mfg.direct_bill = 1 and (ap.inventorytype = 'Rep Delivery' or ap.inventorytype = 'Drop Ship'),'M',
if(fac.dtmcontract = 0 and mfg.direct_bill = 1 and (ap.inventorytype = 'Purchased' or ap.inventorytype = 'Consigned'),'C',
if(fac.dtmcontract = 1 and ap.pay_facility = 0 and ap.facility_orders = 'FacReorder' and ap.inventorytype <> 'Rep Delivery','Z','C')))))
as potype
from actparts ap
.
.
.