Related
I have an access database that I am converting to SQL Server and there is a report that has the follow:
SELECT tblInventoryUnit.[ORG-IU],
tblInventoryUnit.[Parent ORG Name],
tblVehicle.[Asset Tag Number],
tblVehicle.[Vehicle Unit Type],
tblVehicle.[Historical Unit Number],
tblVehicle.[License Plate Number],
tblVehicle.[Model Year],
tblVehicle.Make,
tblVehicle.Model,
tblVehicle.[Acquisition Date],
tblVehicle.[Vehicle Cost],
tblVehicle.[Insurance Account],
tblVehicle.[Insurance Sub-Account],
tblVehicle.[Project Code],
tblFSOTeams.[Fund Accountant Team],
tblVehicle.[Vehicle Status]
FROM tblSPSTeams
RIGHT JOIN(tblFSOTeams
INNER JOIN(tblInventoryUnit
INNER JOIN tblVehicle
ON tblInventoryUnit.[ORG-IU] = tblVehicle.[ORG-IU])
ON tblFSOTeams.[Org Number] = tblInventoryUnit.[Parent ORG])
ON tblSPSTeams.[Account Number] = tblVehicle.[Insurance Account]
WHERE (
((tblVehicle.[Vehicle Unit Type]) <> 'TA')
AND ((tblVehicle.[Acquisition Date]) < '7/15/2020')
AND
(
(tblVehicle.[Vehicle Status]) = 'Pending - Motor Pool'
OR (tblVehicle.[Vehicle Status]) = 'Active - In Use'
OR (tblVehicle.[Vehicle Status]) = 'Active - Unlocated'
OR (tblVehicle.[Vehicle Status]) = 'Active - Surplused'
)
AND ((tblSPSTeams.[SPS Team Number]) IS NULL)
)
OR
(
((tblVehicle.[Vehicle Unit Type]) <> 'TA')
AND ((tblVehicle.[Acquisition Date]) < '7/15/2020')
AND ((tblVehicle.[Vehicle Status]) = 'Inactive')
AND ((tblSPSTeams.[SPS Team Number]) IS NULL)
AND ((tblVehicle.[Disposal Date]) > '7/1/2020')
);
I have figured out from looking at the diagram that this equals:
SELECT tblInventoryUnit.[ORG-IU],
tblInventoryUnit.[Parent ORG Name],
tblVehicle.[Asset Tag Number],
tblVehicle.[Vehicle Unit Type],
tblVehicle.[Historical Unit Number],
tblVehicle.[License Plate Number],
tblVehicle.[Model Year],
tblVehicle.Make,
tblVehicle.Model,
tblVehicle.[Acquisition Date],
tblVehicle.[Vehicle Cost],
tblVehicle.[Insurance Account],
tblVehicle.[Insurance Sub-Account],
tblVehicle.[Project Code],
tblFSOTeams.[Fund Accountant Team],
tblVehicle.[Vehicle Status]
FROM dbo.tblVehicle
LEFT JOIN dbo.tblSPSTeams
ON dbo.tblVehicle.[Insurance Account] = dbo.tblSPSTeams.[Account Number]
INNER JOIN dbo.tblInventoryUnit
ON tblInventoryUnit.[ORG-IU] = tblVehicle.[ORG-IU]
INNER JOIN dbo.tblFSOTeams
ON tblFSOTeams.[Org Number] = dbo.tblInventoryUnit.[Parent ORG]
WHERE (
((tblVehicle.[Vehicle Unit Type]) <> 'TA')
AND ((tblVehicle.[Acquisition Date]) < '7/15/2020')
AND
(
(tblVehicle.[Vehicle Status]) = 'Pending - Motor Pool'
OR (tblVehicle.[Vehicle Status]) = 'Active - In Use'
OR (tblVehicle.[Vehicle Status]) = 'Active - Unlocated'
OR (tblVehicle.[Vehicle Status]) = 'Active - Surplused'
)
AND ((tblSPSTeams.[SPS Team Number]) IS NULL)
)
OR
(
((tblVehicle.[Vehicle Unit Type]) <> 'TA')
AND ((tblVehicle.[Acquisition Date]) < '7/15/2020')
AND ((tblVehicle.[Vehicle Status]) = 'Inactive')
AND ((tblSPSTeams.[SPS Team Number]) IS NULL)
AND ((tblVehicle.[Disposal Date]) > '7/1/2020')
);
Can someone explain how the first query works? I don't get the syntax. In particular, this part:
FROM tblSPSTeams
RIGHT JOIN(tblFSOTeams
INNER JOIN(tblInventoryUnit
INNER JOIN tblVehicle
ON tblInventoryUnit.[ORG-IU] = tblVehicle.[ORG-IU])
ON tblFSOTeams.[Org Number] = tblInventoryUnit.[Parent ORG])
ON tblSPSTeams.[Account Number] = tblVehicle.[Insurance Account]
It looks like two subqueries but there is no select statement in the inner tables. I tried to add a select statement like a "normal" subquery but it balked at the idea. How exactly does this work? Is there a special syntax that I am not getting?
Below is the Query,I had joined 3 tables supplier is main table. The actual scenario is I want all the data from table account payable table though it is not their in purchase order table, so I have joined using FULL Outer with supplier and Purchase Order, but the supplier details were not coming against the data of account payable though supplier key is available.
SELECT ISNULL(dbo.Supplier.supplier_key,dbo.Fact_AccountPayables.supplier_key) AS supplier_key,
dbo.Supplier.Supplier,
dbo.Supplier.Name,
dbo.Supplier.Status,
dbo.Supplier.AddressCode,
dbo.Supplier.Address,
dbo.Supplier.HouseNo,
dbo.Supplier.Street,
dbo.Supplier.City,
dbo.Supplier.Country,
dbo.Supplier.ZipCode,
dbo.Supplier.StartDate,
dbo.Supplier.CreditLimit,
dbo.Supplier.FinancialGroup,
dbo.Supplier.LastTransactionDate,
dbo.Fact_PurchaseOrder.Company,
ISNULL(dbo.Fact_PurchaseOrder.[Purchase Order],dbo.Fact_AccountPayables.[PO Number]) AS PurchaseOrder,
ISNULL( dbo.Fact_PurchaseOrder.Sequence,dbo.Fact_AccountPayables.Line) AS POSequence,
dbo.Fact_PurchaseOrder.[Order Quantity],
dbo.Fact_PurchaseOrder.[Per Purchase Unit],
dbo.Fact_PurchaseOrder.[Per Quantity Price],
dbo.Fact_PurchaseOrder.[Purchase price unit],
dbo.Fact_PurchaseOrder.[Total Order Amount],
dbo.Fact_PurchaseOrder.Currency,
dbo.Fact_PurchaseOrder.[Rate Date],
dbo.Fact_PurchaseOrder.[Actual Receipt Date],
dbo.Fact_PurchaseOrder.[Receipt No],
dbo.Fact_PurchaseOrder.[Receipt Sequence],
dbo.Fact_PurchaseOrder.[Received Quantity],
dbo.Fact_PurchaseOrder.[Approved Quantity],
dbo.Fact_PurchaseOrder.[Purchase Office],
dbo.Fact_PurchaseOrder.[Invoice Number],
dbo.Fact_PurchaseOrder.[Invoice Date],
dbo.Fact_PurchaseOrder.[Invoice Quantity],
dbo.Fact_PurchaseOrder.[Invoice Amount],
dbo.Fact_AccountPayables.InvoiceNumber,
dbo.Fact_AccountPayables.Type AS InvoiceType,
dbo.Fact_AccountPayables.[Order Type] AS OrderInvoiceType,
dbo.Fact_AccountPayables.AP_Balance_EUR,
dbo.Fact_AccountPayables.[Invoice Amount_EUR],
dbo.Fact_AccountPayables.supplier_key AS EXPR2,
dbo.Fact_AccountPayables.[IntercompanyTrade Order No] AS EXPR23,
dbo.Fact_AccountPayables.[IntercompanyTrade Line Number] AS EXPR24,
dbo.Fact_AccountPayables.[Intercompany Trade Financial Company] AS EXPR25,
dbo.Fact_AccountPayables.[Intercompany Trade Purchase Company] AS EXPR26,
dbo.Fact_AccountPayables.InvoiceNumber,
dbo.Fact_AccountPayables.DueDate,
dbo.Fact_AccountPayables.DocDate,
dbo.Fact_PurchaseOrder.[Order Date],
dbo.Fact_AccountPayables.[Invoice Amount_EUR],
(CASE WHEN dbo.Fact_PurchaseOrder.[Receipt No] = ' ' THEN dbo.Fact_PurchaseOrder.[Total Order Amount]
WHEN dbo.Fact_PurchaseOrder.[Receipt No] != ' ' and dbo.Fact_AccountPayables.InvoiceNumber IS NULL then dbo.Fact_PurchaseOrder.[Total Order Amount] END) AS ORDERBALANCE,
(dbo.Supplier.CreditLimit -(ORDERBALANCE + dbo.Fact_AccountPayables.[Invoice Amount_EUR])) AS Availablecredit
FROM dbo.Supplier
LEFT OUTER JOIN dbo.Fact_PurchaseOrder ON dbo.Supplier.supplier_key = dbo.Fact_PurchaseOrder.buyfrom_supplier_key
full OUTER JOIN dbo.Fact_AccountPayables ON dbo.Fact_AccountPayables.supplier_key = dbo.Supplier.supplier_key AND
dbo.Fact_AccountPayables.[PO Number] = dbo.Fact_PurchaseOrder.[Purchase Order] AND
dbo.Fact_AccountPayables.[PO Line] = dbo.Fact_PurchaseOrder.Sequence
The output is like this:
Try your Payable table after that FROM Clause and join the other tables by using LEFT JOIN
FROM dbo.Fact_AccountPayables
LEFT JOIN dbo.Fact_PurchaseOrder ON dbo.Fact_AccountPayables.[PO Number] = dbo.Fact_PurchaseOrder.[Purchase Order] AND
dbo.Fact_AccountPayables.[PO Line] = dbo.Fact_PurchaseOrder.Sequence
LRFT JOIN dbo.Supplier ON dbo.Supplier.supplier_key = dbo.Fact_PurchaseOrder.buyfrom_supplier_key AND dbo.Fact_AccountPayables.supplier_key = dbo.Supplier.supplier_key
You have used not only supplier key, but also PO number and PO line as join criterion with full outer join. If there is no matching entry for these (matching entries for ALL join criteria in the same time) in supplier table you will also see the null values you mentioned.
Just for testing remove temporarily the other join criteria (PO number and line) and leave only the supplier key. Check if you still see the null values in this case.
You're using a FULL join for the Fact_AccountPayables table. This way, all records from Fact_AccountPayables are included even if there are no matches with the other two tables. If you don't want that, use LEFT join instead of FULL join.
SELECT
ISNULL(dbo.Supplier.supplier_key, dbo.Fact_AccountPayables.supplier_key) AS supplier_key,
dbo.Supplier.Supplier,
dbo.Supplier.Name,
dbo.Supplier.Status,
dbo.Supplier.AddressCode,
dbo.Supplier.Address,
dbo.Supplier.HouseNo,
dbo.Supplier.Street,
dbo.Supplier.City,
dbo.Supplier.Country,
dbo.Supplier.ZipCode,
dbo.Supplier.StartDate,
dbo.Supplier.CreditLimit,
dbo.Supplier.FinancialGroup,
dbo.Supplier.LastTransactionDate,
dbo.Fact_PurchaseOrder.Company,
ISNULL(dbo.Fact_PurchaseOrder.[Purchase Order], dbo.Fact_AccountPayables.[PO Number]) AS PurchaseOrder,
ISNULL(dbo.Fact_PurchaseOrder.Sequence, dbo.Fact_AccountPayables.Line) AS POSequence,
dbo.Fact_PurchaseOrder.[Order Quantity],
dbo.Fact_PurchaseOrder.[Per Purchase Unit],
dbo.Fact_PurchaseOrder.[Per Quantity Price],
dbo.Fact_PurchaseOrder.[Purchase price unit],
dbo.Fact_PurchaseOrder.[Total Order Amount],
dbo.Fact_PurchaseOrder.Currency,
dbo.Fact_PurchaseOrder.[Rate Date],
dbo.Fact_PurchaseOrder.[Actual Receipt Date],
dbo.Fact_PurchaseOrder.[Receipt No],
dbo.Fact_PurchaseOrder.[Receipt Sequence],
dbo.Fact_PurchaseOrder.[Received Quantity],
dbo.Fact_PurchaseOrder.[Approved Quantity],
dbo.Fact_PurchaseOrder.[Purchase Office],
dbo.Fact_PurchaseOrder.[Invoice Number],
dbo.Fact_PurchaseOrder.[Invoice Date],
dbo.Fact_PurchaseOrder.[Invoice Quantity],
dbo.Fact_PurchaseOrder.[Invoice Amount],
dbo.Fact_AccountPayables.InvoiceNumber,
dbo.Fact_AccountPayables.Type AS InvoiceType,
dbo.Fact_AccountPayables.[Order Type] AS OrderInvoiceType,
dbo.Fact_AccountPayables.AP_Balance_EUR,
dbo.Fact_AccountPayables.[Invoice Amount_EUR],
dbo.Fact_AccountPayables.supplier_key AS EXPR2,
dbo.Fact_AccountPayables.[IntercompanyTrade Order No] AS EXPR23,
dbo.Fact_AccountPayables.[IntercompanyTrade Line Number] AS EXPR24,
dbo.Fact_AccountPayables.[Intercompany Trade Financial Company] AS EXPR25,
dbo.Fact_AccountPayables.[Intercompany Trade Purchase Company] AS EXPR26,
dbo.Fact_AccountPayables.InvoiceNumber,
dbo.Fact_AccountPayables.DueDate,
dbo.Fact_AccountPayables.DocDate,
dbo.Fact_PurchaseOrder.[Order Date],
dbo.Fact_AccountPayables.[Invoice Amount_EUR],
CASE
WHEN dbo.Fact_PurchaseOrder.[Receipt No] = ' ' THEN dbo.Fact_PurchaseOrder.[Total Order Amount]
WHEN dbo.Fact_AccountPayables.InvoiceNumber IS NULL THEN dbo.Fact_PurchaseOrder.[Total Order Amount]
END AS ORDERBALANCE,
dbo.Supplier.CreditLimit - (ORDERBALANCE + dbo.Fact_AccountPayables.[Invoice Amount_EUR]) AS Availablecredit
FROM
dbo.Supplier
LEFT JOIN dbo.Fact_PurchaseOrder ON dbo.Supplier.supplier_key = dbo.Fact_PurchaseOrder.buyfrom_supplier_key
LEFT JOIN dbo.Fact_AccountPayables ON
dbo.Fact_AccountPayables.supplier_key = dbo.Supplier.supplier_key AND
dbo.Fact_AccountPayables.[PO Number] = dbo.Fact_PurchaseOrder.[Purchase Order] AND
dbo.Fact_AccountPayables.[PO Line] = dbo.Fact_PurchaseOrder.Sequence
Some of the rows are getting filtered in the Fact_PurchaseOrder, if they dont have supplier. You need to go for FULL OUTER JOIN for all tables, to get data for all rows of AccountPayables, irrespective of whether they have got suppliers or not.
FROM dbo.Supplier
FULL OUTER JOIN dbo.Fact_PurchaseOrder ON dbo.Supplier.supplier_key = dbo.Fact_PurchaseOrder.buyfrom_supplier_key
FULL OUTER JOIN dbo.Fact_AccountPayables ON dbo.Fact_AccountPayables.supplier_key = dbo.Supplier.supplier_key AND
dbo.Fact_AccountPayables.[PO Number] = dbo.Fact_PurchaseOrder.[Purchase Order] AND
dbo.Fact_AccountPayables.[PO Line] = dbo.Fact_PurchaseOrder.Sequence
Hey guys I have this report that i am working on. It has multiple Columns and in between those columns are some Left joins. so my question is, how do i add a left join to the query?
Declare #asofdate smalldatetime
Set #asofdate = '2017-08-24'
SELECT
OCCONR as [Company Number],
OCCMNR as [Claim Number], --CMOCUR db)
OCEXCD as [Claim Counsel], ---(CMOCUR db)
DATEFROMPARTS(OCEFCN*100+OCEFYY,OCEFMM,OCEFDD) as [Policy Effective Date], -- (CMOCUR db)
iif([True CAT Nbr] is null, OCCTCD, [True CAT Nbr]) as [CAT Code], ---(Check Comment 1)
iif(LSCMNT is null,'', LSCMNT) as [NOA Comments], --- (Check Comemnt 2)
concat([First_Name],' ',[Last_Name]) as [Insured Name], --- (Check Comment 3)
DatefromParts([OCLSCN]*100+[OCLSYY],[OCLSMM],[OCLSDD]) as [Occurrence Date], --- (CMOCUR db)
rtrim(ltrim(OCDACC)) as [Cause of Loss], --- (CMOCUR db)
DatefromParts([OCRPCN]*100+[OCRPYY],[OCRPMM],[OCRPDD]) as [Claim Reported Date], --- (CMOCUR db)
iif(LSSETLD is null,'', LSSETLD) as [Settled Indicator], --- (Check Comment 2)
--iif(SUM([Incurred Loss NET OF S&S]) - SUM([Paid Loss NET OF S&S]) = 0, 'Closed', 'Open') as [Status in AS-400]
iif(OCCLCN=0,'',datefromparts(OCCLCN*100+OCCLYY,OCCLMM,OCCLDD)) as [Closed Date], --- (CMOCUR db)
iif(LSCLCN=0 OR LSCLCN IS NULL,'',DatefromParts(LSCLCN*100+LSCLYY,LSCLMM,LSCLDD)) as [All Closed Date] ----(Comment 2)
--[Last Reserve Change Date]
FROM AS400.FRTDTA250.CMOCUR
LEFT JOIN Lookups.dbo.[Bad CAT Codes] ON [Claim Nbr] = OCCMNR ---- This LEFT JOIN provides the CAT CODE for this report (Comment 1)
LEFT JOIN AS400.FRTDTA250.CMLSCP ON LSCMNR = OCCMNR ---- This is used to pull any COMMENTS and SETTLEMENT made on a claim (Comment 2)
LEFT JOIN Lookups.dbo.Insured_Name_By_PolicyNum ON Prefix = OCPRFX and Polnum = OCPLNR --- This is to add the INSURED NAME (comment 3)
So, the issue i am having is that i have this other sub-queries that are meant to provide information for the [Status in AS-400] and [Last Reserve Change Date]. How do i connect this queries to the SQL?
Below are the 2 queries that i am trying to add to the select query:
-- Query for [Status in AS-400]
SELECT
---s1.[Claim Number],
iif(SUM(s1.[Incurred Loss NET OF S&S]) - SUM(s1.[Paid Loss NET OF S&S]) = 0, 'Closed', 'Open') as [Open / Closed]
---SUM(s1.[Incurred Loss NET OF S&S]) - SUM(s1.[Paid Loss NET OF S&S]) as [Loss C/R]
FROM
(
SELECT
OCCMNR as [Claim Number],
SUM(iif(DATASETTYPE IN ('Incurred LOSS'), CTTRAM, iif(DATASETTYPE IN ('SALVAGE','SUBROGATION','OTHER RECOVERIES'), -CTTRAM, 0))) AS [Incurred Loss NET OF S&S],
SUM(iif(DATASETTYPE IN ('Paid LOSS'), CTTRAM, iif(DATASETTYPE IN ('SALVAGE','SUBROGATION','OTHER RECOVERIES'), -CTTRAM, 0))) AS [Paid Loss NET OF S&S]
FROM AS400.FRTDTA250.[CMOCUR] AS A
INNER JOIN AS400.FRTDTA250.[CMTRAN]AS B ON A.OCCMNR = B.CTCMNR
LEFT JOIN Lookups.dbo.TransactionCodes AS C ON B.CTGRPC = C.TransactionCode
WHERE DATEFROMPARTS(CTTRCN*100+CTTRYY, CTTRMM, CTTRDD) <= #asofdate
and CTTRSB not in (4,12)
and CTTSCD = 'P'
GROUP BY OCCMNR
) as s1
GROUP BY s1.[Claim Number]
ORDER BY s1.[Claim Number]
--Query for [Last Reserve Change Date]
Select [Claim Number],
left(convert(CHAR, Max([Loss Transaction Date]), 120),10) as [Last Reserve Change Date]
From
(
Select [OCCMNR] as [Claim Number],
DATEFROMPARTS(CTTRCN*100+CTTRYY, CTTRMM, CTTRDD) as [Loss Transaction Date],
iif(DATASETTYPE IN ('Incurred LOSS'), CTTRAM, 0) as [Incurred Loss]
From AS400.FRTDTA250.[CMTRAN] as b1
LEFT JOIN AS400.FRTDTA250.[CMOCUR] as a1
ON a1.OCCMNR = b1.CTCMNR
LEFT JOIN Lookups.dbo.TransactionCodes as c1
ON b1.CTGRPC = c1.TransactionCode
Where (iif(DATASETTYPE IN ('Incurred LOSS'), CTTRAM, 0) <> 0)
and DATEFROMPARTS(CTTRCN*100+CTTRYY, CTTRMM, CTTRDD) <= #asofdate
and CTTRSB not in (4,12)
AND CTTSCD = 'P'
) s2
group by [Claim Number]
) as G
on G.[Claim Number] = a.[OCCMNR]
And i use a MS-SQL Server
Format for joining Sub-queries are as follows:
SELECT *
FROM TABLEA A
INNER JOIN TABLED D on A.ID = D.ID
LEFT JOIN
( SELECT B.ID,COLUMN_A
FROM TABLEB B
INNER JOIN TABLEC C ON B.ID = C.ID
) X ON A.ID = X.ID
I'm after some help please. I only use ms access and beginning to use SQL I have two views part1 and part2 I can't join them and get any results( I have the results from MS access ( see below results part ) . I need the same results to show in SQL )
Thank you..
View (part1)
select Mvpr.Prefix, Mvpr.SubKey1 AS [Parkers Part Number], Mvpr.SubKey2 AS [Supplier Code], Mvpr.A12 AS [Supplier Part Number], vwProduct.Psupp as part1
FROM vwProduct INNER JOIN Mvpr ON vwProduct.KeyCode = Mvpr.SubKey1
WHERE Mvpr.Prefix ='c'
View (part2)
SELECT dbo.RHeads.Document, RLines.Part, RHeads.Supp, RHeads.[DateTime], RLines.Unit, RLines.CQty, RLines.ClCost, RHeads.POrder, RHeads.Corder, RHeads.Branch as part2
FROM RHeads INNER JOIN RLines ON RHeads.Document = RLines.Document
WHERE RHeads.[DateTime] >= DATEADD(MONTH, -3, GETDATE())
Result
SELECT part1.Document, part1.Part [Parkers Part], part2.[Supplier Part Number], part1.Supp [Supplier Code], part1.Unit [Unit Price], part1.CQty [Qty Recieved], dbo.vwProduct.SI18 Surcharge, part1.POrder, part1.Corder, part1.Branch, part1.DateTime
FROM dbo.vwProduct INNER JOIN part2 INNER JOIN part1 ON part2.[Supplier Code] = part1.Supp AND part2.[Parkers Part Number] = part1.Part ON dbo.vwProduct.KeyCode = part1.Part
GROUP BY part1.Document, part1.Part, part2.[Supplier Part Number], part1.Supp, part1.Unit, part1.CQty, dbo.vwProduct.SI18, part1.POrder, part1.Corder, part1.Branch, part1.DateTime
Based on your SQL in Result section, your View (part2) should be your part1 since columns such as Document, Part, etc. are coming from that and vice versa.
SELECT part1.Document,
part1.Part [Parkers Part],
part2.[Supplier Part Number],
part1.Supp [Supplier Code],
part1.Unit [Unit Price],
part1.CQty [Qty Recieved],
dbo.vwProduct.SI18 Surcharge,
part1.POrder,
part1.Corder,
part1.Branch,
part1.DateTime
FROM dbo.vwProduct
INNER JOIN part1
ON dbo.vwProduct.KeyCode = part1.Part
INNER JOIN part2
ON part2.[Supplier Code] = part1.Supp
AND part2.[Parkers Part Number] = part1.Part
GROUP BY part1.Document,
part1.Part,
part2.[Supplier Part Number],
part1.Supp,
part1.Unit,
part1.CQty,
dbo.vwProduct.SI18,
part1.POrder,
part1.Corder,
part1.Branch,
part1.DateTime
SELECT ap.ID, ap.[Adjustment Name], ap.[Adjustment Name Description], ap.[2nd Item Number], [ap].Description, ap.[Unit of Measure], ap.[Effective Date], ap.[Expired Date], MAX( ap.[Factor Value Numeric] ) , ap.[Prc Cls], ap.[Prc Cls Description], ap.[Address Number], ap.[Sales Detail Value 01], ap.[Currency Code], c.[Customer Pricing Rule], c.[Alpha Name]
FROM [Adv Price Query Export] ap
INNER JOIN ( SELECT [Adjustment Name], [2nd Item Number], MAX([Effective Date]), [Factor Value Numeric], [Sales Detail Value 01]
FROM [Adv Price Query Export] ) s ON ((s.[Adjustment Name] = ap.[Adjustment Name]) AND (s.[Effective Date] = ap.[Effective Date]) AND (s.[Sales Detail Value 01] = ap.[Sales Detail Value 01]))
INNER JOIN Customer c ON (ap.[Adjustment Name] = c.[Adjustment Schedule])
WHERE ( ap.[2nd Item Number] = "18500" OR ap.[2nd Item Number] = "185047" OR ap.[2nd Item Number] = "18550" OR ap.[2nd Item Number] = "26004" OR ap.[2nd Item Number] = "55010" )
GROUP BY ap.[Sales Detail Value 01]
Not sure where the error is but you can re-write your query like below
SELECT ap.ID,
ap.[Adjustment Name],
ap.[Adjustment Name Description],
ap.[2nd Item Number],
[ap].Description,
ap.[Unit of Measure],
ap.[Effective Date],
ap.[Expired Date],
MAX( ap.[Factor Value Numeric] ) ,
ap.[Prc Cls],
ap.[Prc Cls Description],
ap.[Address Number],
ap.[Sales Detail Value 01],
ap.[Currency Code],
c.[Customer Pricing Rule],
c.[Alpha Name]
FROM [Adv Price Query Export] ap
INNER JOIN ( SELECT [Adjustment Name],
[2nd Item Number],
MAX([Effective Date]),
[Factor Value Numeric],
[Sales Detail Value 01]
FROM [Adv Price Query Export] ) s
ON s.[Adjustment Name] = ap.[Adjustment Name]
AND s.[Effective Date] = ap.[Effective Date]
AND s.[Sales Detail Value 01] = ap.[Sales Detail Value 01]
INNER JOIN Customer c ON ap.[Adjustment Name] = c.[Adjustment Schedule]
WHERE ap.[2nd Item Number] IN ("18500", "185047", "18550", "26004", "55010" )
GROUP BY ap.[Sales Detail Value 01]