Trying to read a data base 4 file and getting an error - sql

I'm trying to read 5 DBF files, MINFODIV.DBF, MINFO.DBF, MODE.DBF, DIVISION.DBF, MENU.DBF using SQL statements. No problems reading each individually into a table using VB.Net. I created the following SQL statement using Flyspeed SQL Query on the files and it works.
In VB.net I get
"Syntax error (missing operator) in query expression
'midb1.AMOUNT
From MINFODIV.DBF midb1
Inner Join MINFO.DBF midb On midb1.MINFOID = midb.MINFOID
Inner Join MODE.DBF modb On midb.MODEID = modb.MODEID
Inner Join MENU.DBF medb On modb.MENUID = medb.MENUID
Inner Join DIVISION.DBF didb On didb.DIVISIONID = midb1.DIVISIONID'"
My select statement is as follows:
Select
modb.DESC,
medb.DESC As DESC1,
didb.DESC As DESC2,
midb1.AMOUNT
From
MINFODIV.DBF midb1
Inner Join MINFO.DBF midb On midb1.MINFOID = midb.MINFOID
Inner Join MODE.DBF modb On midb.MODEID = modb.MODEID
Inner Join MENU.DBF medb On modb.MENUID = medb.MENUID
Inner Join DIVISION.DBF didb On didb.DIVISIONID = midb1.DIVISIONID

Related

MSAccess UPDATE on INNER JOIN on INNER JOIN

I need some help with an update statement in MS Access.
(The statement was written by a former employee. The SQL statement itself was built automatically through using the graphical editor.)
The full statement:
UPDATE
(((dbo_customer AS c
INNER JOIN dbo_priceGrpD AS pd
ON c.Nr = pd.Nr)
INNER JOIN dbo_priceGrp AS p
ON p.grp = pd.grp)
INNER JOIN dbo_customerGrp AS cg
ON c.grp = cg.grp)
SET k.U2021 = 0
It works fine if I remove the second and the third INNER JOIN:
UPDATE
dbo_customer AS c
INNER JOIN dbo_priceGrpD AS pd
ON c.Nr = pd.Nr
SET k.Umsatz2021 = 0
The error from Access on executing the full statement: "Operation must use an updateable query." (Error 3073)

3 inner joins and a left join in my FROM statement

I am debugging some code for an MS Access program with a SQL backend. One of the queries is producing the following error: "the expression on click you entered as the event property setting produced the following error:
cannot join on Memo, OLE, or Hyperlink Object (master_export.item=vw_items.Item)"
This is the original code:
SELECT master_export_pt.commitment_number AS [Commitment Number],
Sum(master_export_pt.receipt_amount) AS Amount,
LocalLocation.Location_Name AS Child_Location_Name,
LocalLocation_1.Location_Name AS Parent_Location_Name,
BypassLocation.JNL_Sales AS ByPassSales,
BypassLocation.JNL_COGS AS ByPassCogs,
master_export_pt.order_type
FROM (((master_export_pt
INNER JOIN vw_items ON master_export_pt.item = vw_items.Item)
INNER JOIN BypassLocation ON master_export_pt.location_id = BypassLocation.location_id)
INNER JOIN LocalLocation ON BypassLocation.location_id = LocalLocation.Location_ID)
LEFT JOIN LocalLocation AS LocalLocation_1
ON LocalLocation.parent_location_id = LocalLocation_1.Location_ID
and tried changing the first JOIN to:
FROM (((master_export_pt, vw_items)
where (master_export_pt.item = vw_items.Item))
INNER JOIN BypassLocation ON master_export_pt.location_id = BypassLocation.location_id)
INNER JOIN LocalLocation ON BypassLocation.location_id = LocalLocation.Location_ID)
LEFT JOIN LocalLocation AS LocalLocation_1
ON LocalLocation.parent_location_id = LocalLocation_1.Location_ID
but now i get the "Syntax error in JOIN operation" error message. Is there a way to re-write the query without using nested JOIN statements?
Thank you to all who responded. I tried the following code and it seems to have done the trick:
SELECT
xxx.commitment_number AS [Commitment Number],
Sum(xxx.receipt_amount) AS Amount,
xxx.Location_Name AS Child_Location_Name,
xxx.Location_Name AS Parent_Location_Name,
xxx.JNL_Sales AS ByPassSales,
xxx.JNL_COGS AS ByPassCogs,
xxx.order_type
FROM (
SELECT * FROM
master_export_pt AS mept, vw_items AS vi, BypassLocation AS bl, LocalLocation AS ll
WHERE mept.item = vi.Item
AND mept.location_id = bl.location_id
AND bl.location_id = ll.Location_ID) AS xxx
LEFT OUTER JOIN LocalLocation AS ll1 ON xxx.parent_location_id = ll1.Location_ID
GROUP BY
xxx.commitment_number,
xxx.Location_Name,
ll1.Location_Name,
xxx.JNL_Sales,
xxx.JNL_COGS,
xxx.order_type;

How to join 7 tables in SQL using INNER JOIN

I am creating a stored procedure to join 7 tables in SQL using INNER JOIN, however I am getting an error about incorrect syntax.
I've tried to adjust formatting but I cannot get the syntax correct. Does anyone know where I've gone wrong? I get an error stating
Incorrect syntax near "WHERE"
My code:
CREATE PROCEDURE [dbo].[spInvoicing]
#InvoiceId INT
AS
BEGIN
SELECT
tblInvoices.InvoiceId, tblInvoices.InvoiceDate,
tblClients.Firstname, tblClients.Surname, tblClients.Address, tblClients.City,
tblClients.Postcode, tblClients.Email, tblClients.Phone,
tblAppointments.AppointmentId, tblAppointments.DateOfAppointment,
tblProductsUsed.ProductsUsedId, tblProducts.ProductName, tblProductsUsed.Quantity,
tblPointofSale.SaleId, tblPointOfSale.CostOfProducts, tblPointOfSale.CostOfServices,
tblPointOfSale.VAT, tblInvoices.SaleAmount, tblInvoices.PaymentMethod
FROM
tblClients
INNER JOIN
tblAppointments ON tblClients.ClientId = tblAppointments.ClientId
INNER JOIN
tblPointOfSale
INNER JOIN
tblInvoices ON tblPointOfSale.SaleId = tblInvoices.SaleId
INNER JOIN
tblProductsUsed
INNER JOIN
tblProducts ON tblProductsUsed.ProductId = tblProducts.ProductId
INNER JOIN
tblServicesRendered
INNER JOIN
tblServices ON tblServicesRendered.ServiceId = tblServices.ServiceId ON tblServicesRendered.AppointmentId = tblAppointments.AppointmentId
ON tblPointOfSale.AppointmentId = tblAppointments.AppointmentId
AND tblProductsUsed.SaleId = tblPointOfSale.SaleId
AND tblPointOfSale.ClientId = tblClients.ClientId
WHERE
tblInvoices.InvoiceId = #InvoiceId
END
Your JOINs got a bit scrambled. Try this below, and see if that fixes the syntax error.
Always try to get your JOINs to follow the format INNER JOIN [Table2] ON [Table2].[Field1] = [Table1].[Field1]
FROM tblClients
INNER JOIN tblAppointments ON tblClients.ClientId = tblAppointments.ClientId
INNER JOIN tblPointOfSale ON tblPointOfSale.AppointmentId = tblAppointments.AppointmentId
AND tblPointOfSale.ClientId = tblClients.ClientId
INNER JOIN tblInvoices ON tblPointOfSale.SaleId = tblInvoices.SaleId
INNER JOIN tblProductsUsed ON tblProductsUsed.SaleId = tblPointOfSale.SaleId
INNER JOIN tblProducts ON tblProductsUsed.ProductId = tblProducts.ProductId
INNER JOIN tblServicesRendered ON tblServicesRendered.AppointmentId = tblAppointments.AppointmentId
INNER JOIN tblServices ON tblServicesRendered.ServiceId = tblServices.ServiceId
I just copy and pasted your code into this website - http://poorsql.com/
and it hightlighted the error for you (you're missing AND in the joins).
As #DBro said - get in the habit of putting your JOINs on the new line and format it a little differently, and you'll have far less trouble.

Difference between SQL joins

When I change this:
FROM "Server"."dbo"."SalesTable" "SalesTable"
INNER JOIN "Server"."dbo"."ItemTable" "ItemTable"
ON "ItemTable"."ItemKey"="SalesTable"."ItemKey"
INNER JOIN "Server"."dbo"."ItemClassTable" "ItemClassTable"
ON "ItemTable"."ItemClassKey" = "ItemClassTable"."ItemClassKey"
INNER JOIN "Server"."dbo"."ItemDescriptionTable" "ItemDescriptionTable"
ON "ItemTable"."ItemKey"="ItemDescriptionTable"."ItemKey"
INNER JOIN "Server"."dbo"."timSalesProdLine" "timSalesProdLine"
ON "ItemTable"."SalesLineKey"="timSalesProdLine"."SalesLineKey"
INNER JOIN "Server"."dbo"."InventoryTable" "InventoryTable"
ON "ItemTable"."ItemKey" = "InventoryTable"."ItemKey"
INNER JOIN "Server"."dbo"."AccountTable" "AccountTable"
ON "InventoryTable"."SalesAcctKey"="AccountTable"."GLAcctKey"
INNER JOIN "Server"."dbo"."CustomerTable" "CustomerTable"
ON "CustomerTable"."CustKey" = "SalesTable"."CustKey"
To this:
FROM "Server"."dbo"."SalesTable" "SalesTable"
INNER JOIN "Server"."dbo"."itemTable" "itemTable"
ON "itemTable"."ItemKey"="SalesTable"."ItemKey"
INNER JOIN "Server"."dbo"."itemClassTable" "itemClassTable"
ON "itemTable"."ItemClassKey" = "itemClassTable"."ItemClassKey"
INNER JOIN "Server"."dbo"."ItemDescriptionTable" "ItemDescriptionTable"
ON "itemTable"."ItemKey"="ItemDescriptionTable"."ItemKey"
INNER JOIN "Server"."dbo"."timSalesProdLine" "timSalesProdLine"
ON "itemTable"."SalesLineKey"="timSalesProdLine"."SalesLineKey"
INNER JOIN "Server"."dbo"."inventoryTable" "inventoryTable"
ON "SalesTable"."WarehouseKey" = "inventoryTable"."WarehouseKey"
INNER JOIN "Server"."dbo"."AccountTable" "AccountTable"
ON "inventoryTable"."SalesAcctKey"="AccountTable"."GLAcctKey"
INNER JOIN "Server"."dbo"."CustomerTable" "CustomerTable"
ON "CustomerTable"."CustKey" = "SalesTable"."CustKey"
I get an error message.
I am using an ODBC connection via Excel and the error message is: "[DBNETLIB][ConnectionRead (recv()).] General network error. Check your network documentation."
When I try to run through a command in Crystal Reports, the error message is the same except it ends with: "[Database Ventor Code: 11]".
Only change is join 5 where I attempt to link the tables with "WarehouseKey".
What can I do differently?
I omitted the rest of my query because it's the same in both scenarios. Of course, if needed, I can add via edit.

Ambiguous outer join in MS Access

Trying to create an outer join on two other joined tables when recieving this error - I just dont see how to create two separate queries to make it work. Subqueries don't seem to work either, any help appreciated. I get errors for the below query, thanks.
SELECT
CardHeader.CardID, CardHeader.CardDescription, CardHeader.GloveSize,
CardHeader.GloveDescription, CardDetail.Bin, CardDetail.ItemID, Items.ItemDescription,
Items.VCatalogID, CardDetail.ChargeCode, CardDetail.Quantity, Items.Cost, CardColors.ColorID
FROM
((Items
INNER JOIN
(CardHeader INNER JOIN CardDetail ON CardHeader.CardID = CardDetail.CardID) ON Items.ItemID = CardDetail.ItemID)
LEFT JOIN
CardColors ON CardDetail.ItemID = CardColors.ItemID)
INNER JOIN
Colors ON CardColors.ColorID = Colors.ID
ORDER BY
CardHeader.CardID;
I tried the following which runs but asks for the following parameters (which it shouldnt)
CardHeader.ID, MainQry.CardID
SELECT
MainQry.ID, MainQry.CardDescription, MainQry.GloveSize,
MainQry.GloveDescription, MainQry.Bin, MainQry.ItemID,
MainQry.ItemDescription, MainQry.VCatalogID, MainQry.ChargeCode,
MainQry.Quantity, MainQry.Cost, SubQry.ColorID
FROM
(SELECT
CardHeader.ID, CardHeader.CardDescription, CardHeader.GloveSize,
CardHeader.GloveDescription, CardDetail.Bin,
CardDetail.ItemID, Items.ItemDescription, Items.VCatalogID,
CardDetail.ChargeCode, CardDetail.Quantity, Items.Cost
FROM
Items
INNER JOIN
(CardHeader
INNER JOIN
CardDetail ON CardHeader.CardID = CardDetail.CardID) ON Items.ItemID = CardDetail.ItemID
) AS MainQry
LEFT JOIN
(SELECT
CardColors.ItemID, CardColors.ColorID
FROM
CardColors
INNER JOIN
Colors ON CardColors.ColorID = Colors.ID) AS SubQry ON MainQry.ItemID = SubQry.ItemID
ORDER BY
MainQry.CardID;
The second SQL statement can be corrected by reference to the first statement and the error. The error is that both CardHeader.ID and MainQry.CardID are prompting for a parameter, which indicates that the inner statement should include CardHeader.CardID, rather than CardHeader.ID