Forum Moderators: open
SELECT
workorder-fields,
CASE
WHEN workorder-table.Status = 'open' THEN
SELECT customer-fields, billing-fields FROM live-customer-table , live-billing-table
WHERE live-customer-table.customerID = workorder-table.customerID AND live-billing-table.billingID = workorder-table.billingID
WHEN workorder-table.Status = 'closed' THEN
SELECT customer-fields, billing-fields FROM snapshot-customer-table, snapshot-billing-table
WHERE snapshot-customer-table.workorderID = workorder-table.workorderID AND snapshot-billing-table.workorderID = workorder-table.workorderID
END
FROM workorder-table
$sql = 'SELECT
wo.WOID,
.
.
SELECT SUM(wi.UnitPrice * wi.QTY) FROM '.$crudTable['wo-items-wi'].' AS wi WHERE wi.WOID = wo.WOID) AS SubTotal,
.
.
wo.WSID,
.
.
(SELECT COUNT(*) FROM '.$crudTable['wo-items-wi'].' AS wi WHERE wo.WOID = wi.WOID) AS ChildRecords,
st.TaxRate';
FROM '.$crudTable['workorder-wo'].' AS wo';
INNER JOIN '.$crudTable['user-ur'].' AS ur ON wo.URID = ur.URID';
LEFT JOIN '.$crudTable['member-me'].' AS me ON ur.MEID = me.MEID';
LEFT JOIN '.$crudTable['customer-cu'].' AS cu ON wo.WOID = cu.WOID';
LEFT JOIN '.$crudTable['cu-status-cs'].' AS cs ON cu.CSID = cs.CSID';
LEFT JOIN '.$crudTable['cu-billing-address-ba'].' AS ba ON wo.WOID = ba.WOID';
LEFT JOIN '.$crudTable['state-st'].' AS st ON cu.State = st.StateAbbrev';
LEFT JOIN '.$crudTable['wo-service-wv'].' AS wv ON wo.SVID = wv.SVID';
LEFT JOIN '.$crudTable['wo-lead-source-ls'].' AS ls ON wo.LSID = ls.LSID';
LEFT JOIN '.$crudTable['wo-timeblock-tb'].' AS tb ON wo.TBID = tb.TBID';
LEFT JOIN '.$crudTable['wo-status-ws'].' AS ws ON wo.WSID = ws.WSID';
LEFT JOIN '.$crudTable['franchise-fr'].' AS fr ON wo.FRID = fr.FRID';
WHERE wo.FRID LIKE "'.$_SESSION['FRID'].'"';