SQL query to import data

DWig

Board Regular
Joined
Sep 26, 2012
Messages
77
Here I go again.

I'm trying to write a SQL query to pull a distinct list of outstanding purchases. This works in MS Access, but when I translate it to SQL (remove dbo_ from the tables, change " to ') it claims the syntax is off.

Specifically it says "Incorrect syntax near the keyword "Purchase".

Code:
SELECT DISTINCT Purchase.PurchaseNumber, Purchase.PurchaseDate, Purchase.PurchaseAmount, Company.LegalName, GLAccounts.GLAccount_Code, Purchase.Reconciliation_Key, CustomerAccount.CustomerName

FROM 
((Purchase INNER JOIN GLAccounts ON Purchase.GLAccount_Key = GLAccounts.GLAccount_Key) INNER JOIN BatchControl ON Purchase.BatchControl_Key = BatchControl.BatchControl_Key) 


INNER JOIN (Company INNER JOIN CustomerAccount ON Company.Company_Key = CustomerAccount.Company_Key) ON (BatchControl.Company_Key = Company.Company_Key) AND (GLAccounts.GLAccount_Key = CustomerAccount.GLAccount_Key)






INNER JOIN CompanyUserFields ON Company.Company_Key = CompanyUserFields.Company_Key


WHERE Purchase.Reconciliation_Key Is Null AND CompanyUserFields.Rollup="Aggregated"
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
SELECT DISTINCT
Purchase.PurchaseNumber
, Purchase.PurchaseDate
, Purchase.PurchaseAmount
, Company.LegalName
, GLAccounts.GLAccount_Code
, Purchase.Reconciliation_Key
, CustomerAccount.CustomerName

FROM Purchase JOIN GLAccounts
ON Purchase.GLAccount_Key = GLAccounts.GLAccount_Key

JOIN BatchControl
ON Purchase.BatchControl_Key = BatchControl.BatchControl_Key

JOIN Company
ON BatchControl.Company_Key = Company.Company_Key

JOIN CustomerAccount
ON Company.Company_Key = CustomerAccount.Company_Key
AND GLAccounts.GLAccount_Key = CustomerAccount.GLAccount_Key

JOIN CompanyUserFields
ON Company.Company_Key = CompanyUserFields.Company_Key


WHERE Purchase.Reconciliation_Key Is Null
AND CompanyUserFields.Rollup='Aggregated'
 
Upvote 0

Forum statistics

Threads
1,214,389
Messages
6,119,232
Members
448,879
Latest member
VanGirl

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top