SQL help with Serial #'s
Hello all. I am attempting to write a SQL query that will pull the Sales Order #, Any items in that Sales Order and their respective Serial #'s (If any). The problem with my query is that I am pulling Serial #'s that don't even exist for that particular item. I created a drill down to the Item Master Data for each item, and if I click on my drill down, the serial & batch # option is managed by: "None". I do not want to pull any serial #'s unless this particular item is "Managed by Serial #". I don't know what I'm doing wrong.
SELECT Distinct RDR1.DocEntry, SRI1.ItemCode AS Item, SRI1.ItemName AS Description, SRI1.BaseType, OSRI.IntrSerial AS Serial, ORDR.DocNum, SRI1_1.ItemCode, OSRI.Quantity FROM OSRI INNER JOIN SRI1 ON OSRI.ItemCode = SRI1.ItemCode AND OSRI.SysSerial = SRI1.SysSerial INNER JOIN ORDR ON SRI1.BaseEntry = ORDR.DocEntry INNER JOIN SRI1 AS SRI1_1 ON OSRI.ItemCode = SRI1_1.ItemCode INNER JOIN ODLN ON SRI1_1.BaseEntry = ODLN.DocEntry INNER JOIN RDR1 ON ORDR.DocEntry = RDR1.DocEntry
If someone could see what I'm doing wrong, it would be greatly appreciated. Thanks in advance.