Jump to content

Urgent: Return results if not in specific table + column


aebstract

Recommended Posts

Title sucks, not sure what to name it. Anyway, I've got a database with lots of tables and lots of information. (our inventory management software) I'm doing something where I am returning results of orders, and I need to only return it if "SO.ID" does not show up in "POSTRANSACTION.SOID". Basically in the query I have "AND POSTRANSACTION.SOID = SO.ID" which did the exact opposite of what I needed (obviously). So it is only showing the orders that are in the postransaction table right now, and it needs to only show ones that AREN'T. Is there a simple query word or two I can use to do this?

Link to comment
Share on other sites

Okay I tried adding the bit you put in to the code, and got an error. Here is the code to look at + the error:

 

SELECT SO.num AS "SO", SO.dateCompleted AS "DateCompleted", SO.dateIssued as "DateIssued",
    COALESCE(SO.totalTax, 0) as "Tax", COALESCE(POSTransaction.Amount, 0) AS "POSAmount",
    POSTransaction.dateTime as "POSDate", PaymentMethod.name AS "PaymentName", Customer.name as "Customer", so.customerpo as "customerpo",
    COALESCE(SUM(SOItem.totalPrice), 0) AS totalPrice, MAX(SOItem.dateScheduledFulfillment) AS DateScheduledFulfillment,
    PaymentTerms.netDays as "NetDays", PaymentTerms.nextMonth as "NextMonth",
    PaymentMethod.Name as "PaymentType", company.name AS company, COALESCE(postcatch.totalpaid, 0) AS totalpaid,
    COALESCE(postcatchcount.countpaid,1) as catchcount

FROM Customer, SOItem, PaymentTerms, SO
    LEFT JOIN POSTransaction ON POSTransaction.soID = SO.ID
    LEFT JOIN PaymentMethod ON PaymentMethod.ID = POSTransaction.paymentMethodID
    JOIN company ON company.id = 1
    LEFT JOIN (SELECT SUM(amount) AS totalpaid, soid
                 FROM postransaction
                GROUP BY soid) postcatch ON postcatch.soid = so.id
    LEFT JOIN (SELECT Count(amount) AS countpaid, soid
                 FROM postransaction
                GROUP BY soid) postcatchCount ON postcatchCount.soid = so.id
    LEFT OUTER JOIN postransaction ON SO.ID = POSTRANSACTION.SOID


WHERE Customer.ID = SO.customerID
AND SOItem.SOID = SO.ID
AND PaymentTerms.ID = SO.paymentTermsID
AND SOItem.typeID <> 40
AND Customer.ID LIKE $P{customerID}
AND SOItem.statusID <> 70
AND SO.statusID IN($P{ckIssued},$P{ckInProgress},$P{ckFulfilled},$P{ckClosedShort})
AND POSTRANSACTION.SOID IS NULL

GROUP BY SO.num, SO.dateCompleted, SO.dateIssued, SO.statusID, SO.totalTax,
    POSTransaction.amount, POSTransaction.dateTime, PaymentMethod.name, Customer.name,
    PaymentTerms.netDays, PaymentTerms.typeID, PaymentTerms.nextMonth, company.name,
    postcatch.totalpaid, postcatchcount.countpaid, so.customerpo

ORDER BY Customer.name, SO.num, POSTransaction.dateTime

 

 

Error:SQL problems:GDS Exception. 335544569. Dynamic SQL ErrorSQL error code = -204Ambiguous field name between table POSTRANSACTION and table POSTRANSACTION SOID

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.