I'm trying to query several different tables using INNER JOINs but there's something missing in my code. I get all the results I need except that what I want in this case is that for example, when we make partial shipments, I need to have all the different shipping dates, not just the latest one. Here's the code, maybe someone can help me:
SELECT somast.fcompany AS CUSTOMER, somast.fstatus AS [SALES ORDER STATUS], SUBSTRING(a.fsokey, 1, 6) AS [SO #], SUBSTRING(a.fsokey, 7, 3) AS [SALES ORDER ITEM #],
a.fpartno AS [PART #], a.frev AS [PART REV], a.forderqty AS [ORDER QTY], sorels.fduedate AS [DUE DATE], a.fshipqty AS [SHIP QTY],
shmast.fshipdate AS [SHIP DATE], a.fshipno AS [SHIPPING #], sorels.funettxnpric AS [SALES ORDER $ UNIT USD], sorels.funetprice AS [SALES ORDER $ UNIT MEX],
sorels.funettxnpric * b.fquantity AS [ORD QTY $ TOT USD], sorels.funetprice * b.fquantity AS [ORD QTY SO $ TOT MEX],
sorels.funettxnpric * a.fshipqty AS [SHIP QTY $ TOT USD], sorels.funetprice * a.fshipqty AS [SHIP QTY $ TOT MEX], YEAR(b.fduedate)
AS [DUE DATE YEAR], MONTH(b.fduedate) AS [DUE DATE MONTH]
FROM shmast INNER JOIN
shitem a ON shmast.fshipno = a.fshipno RIGHT OUTER JOIN
sorels INNER JOIN
soitem b ON sorels.fenumber = b.fenumber AND sorels.fsono = b.fsono INNER JOIN
somast ON b.fsono = somast.fsono ON SUBSTRING(a.fsokey, 1, 6) + SUBSTRING(a.fsokey, 7, 3) = b.fsono + b.finumber
WHERE (LEN(a.fsokey) <> 0) AND (YEAR(b.fduedate) > '2010')
ORDER BY sorels.fduedate
Any suggestions will be greatly appreciated.