Query is too complex error in ms access? - sql

I tried to bind 3 queries into single query, using this code but when i click "Datasheet View" it showing error "QUERY IS TOO COMPLEX".
This is my code
SELECT
RPT_Invoice_Less.InvoiceNumber,
RPT_Invoice_Less.Terms,
RPT_Invoice_Less.Invoicedate,
RPT_Invoice_Less.OurQuote,
RPT_Invoice_Less.SalesPerson,
RPT_Customer.CustomerName,
RPT_Customer.CustomerId,
RPT_Customer.ContactPerson,
RPT_Customer.BillingAddress,
RPT_Customer.DeliveryAddress,
RPT_Invoice_Less.OrderNumber,
RPT_Invoice_Less.ShippingBy,
RPT_Invoice_Less.ShipReferenceNo,
RPT_Invoice_Less.Notes,
RPT_Invoice_Less.Price,
RPT_Invoice_Less.Discount,
RPT_Invoice_Less.Shipping,
RPT_Invoice_Less.Tax,
RPT_Invoice_Less.GrandTotal,
RPT_Company.CompanyName,
RPT_Company.CompanyId,
RPT_Company.RegistrationNumber,
RPT_Company.Address,
RPT_Company.MobileNumber,
RPT_Company.FaxNumber,
RPT_Company.CompanyEmail,
RPT_Company.CompanyWebsite,
RPT_Company.VatTinNumber
FROM
(RPT_Invoice_Less
INNER JOIN RPT_Customer
ON RPT_Invoice_Less.CustomerId=RPT_Customer.CustomerId)
INNER JOIN
RPT_Company
ON RPT_Invoice_Less.CompanyId=RPT_Company.CompanyId;

Try to use the built in designer to reproduce as close as you can, if not replicate the query, I get the impression looking at that there maybe an issue around the FROM part of that query

Thank you guys finally I solved with your ideas and my current code i pasted below
SELECT RPT_Invoice_Less.InvoiceNumber, RPT_Invoice_Less.Terms, RPT_Invoice_Less.Invoicedate, RPT_Invoice_Less.OurQuote, RPT_Invoice_Less.SalesPerson,
RPT_Customer.CustomerName, RPT_Customer.CustomerId, RPT_Customer.ContactPerson, RPT_Customer_Address.BillingAddress, RPT_Customer_Address.DeliveryAddress, RPT_Invoice_Less.OrderNumber, RPT_Invoice_Less.ShippingBy, RPT_Invoice_Less.ShipReferenceNo, RPT_Invoice_Less.Notes, RPT_Invoice_Less.Price, RPT_Invoice_Less.Discount, RPT_Invoice_Less.Shipping, RPT_Invoice_Less.Tax, RPT_Invoice_Less.GrandTotal,
RPT_Company.CompanyName, RPT_Company.CompanyId, RPT_Company.RegistrationNumber, RPT_Company_Address.Address, RPT_Company.MobileNumber, RPT_Company.FaxNumber, RPT_Company.CompanyEmail, RPT_Company.CompanyWebsite, RPT_Company.VatTinNumber
FROM (((RPT_Invoice_Less INNER JOIN RPT_Customer ON RPT_Invoice_Less.CustomerId = RPT_Customer.CustomerId) INNER JOIN RPT_Company ON RPT_Invoice_Less.CompanyId = RPT_Company.CompanyId) INNER JOIN RPT_Company_Address ON RPT_Invoice_Less.CompanyId = RPT_Company_Address.AddressId) INNER JOIN RPT_Customer_Address ON RPT_Invoice_Less.CustomerId = RPT_Customer_Address.CustomerId;
This code working successfull.

Related

SQL Query for Reporting

I am trying to join two tables and getting the data for my report. Is there any best way to get the details as per below report?
I have tried below query and getting the results. Please find my query.
SELECT wl.trasaction_id
,wl.supplier_id
,wl.sp_patientpid
,wl.dm_id AS original_dm_id
,NVL(cr.new_dm_id,wl.dm_id) AS out_dm_id
FROM weekly_load wl
LEFT JOIN cross_ref cr
ON wl.sp_patientpid = cr.sp_patient_id
AND wl.supplier_id = cr.ims_supplier_id
Kindly help me.
Many thanks.
You may need an additional join condition on the dm ids:
SELECT wl.trasaction_id, wl.supplier_id, wl.sp_patientpid, wl.dm_id AS original_dm_id,
COALESCE(cr.new_dm_id, wl.dm_id) AS out_dm_id
FROM weekly_load wl LEFT JOIN
cross_ref cr
ON wl.sp_patientpid = cr.sp_patient_id AND
wl.supplier_id = cr.ims_supplier_id AND
wl.dm_id = cr.old_dm_id;

MS Access 2016 Error: "Multi-level group by not allowed"

i'm stuck at another point in my little Access 2016 Database. My code looks like the following and i know it probably isn't the cleanest solution but i'm kinda new to this and i tried to educate myself and get some help here already.
I'm trying to play around with the reports now a little bit and i am using this test query which returns all entries of two tables joined together.
As far as i could find out I have this one subquery included that returns the prvious day inventory for each record and that is most likely the cause of my error. I found a possible solution with adding SELECT * FROM at the beginning of my code but i get a Syntax error when i do that and i'm not sure how to solve this problem.
here's my code
SELECT Stations.StationName, Product.ProductName, GasInventoryTransactions.TransactionDate, (SELECT TOP 1 Dupe.ActualInventory FROM GasInventory AS Dupe WHERE Dupe.StationID = Stations.StationID AND Dupe.ProductID = Product.ProductID AND Dupe.InventoryDate < GasInventory.InventoryDate ORDER BY Dupe.InventoryDate DESC) AS PreviousDayInventory, GasInventory.ActualInventory, GasInventoryTransactions.GasSales, GasInventoryTransactions.GasDelivery, [PreviousDayInventory]+[GasDelivery]-[GasSales] AS BookBalance, GasInventory.ActualInventory, [ActualInventory]-[BookBalance] AS OverShort
FROM (Stations INNER JOIN (Product INNER JOIN GasInventory ON Product.[ProductID] = GasInventory.[ProductID]) ON Stations.[StationID] = GasInventory.[StationID]) INNER JOIN GasInventoryTransactions ON GasInventory.[InventoryDate] = GasInventoryTransactions.[TransactionDate];
thanks for your help!

Error Trying to do Left Outer Join BigQuery

I'm trying to do a relatively simple outer join but quite new to Big Query and I'm getting the following Error: internal error: missing closing bracket at: 2.3 - 2.39
SELECT
([130493328.ga_sessions_20170312].date),
([130493328.ga_sessions_20170312].total.visits),
([130493328.social].engagedUsers)
FROM ([130493328.ga_sessions_20170312]),
LEFT OUTER JOIN
[130493328.social]
ON
([130493328.ga_sessions_20170312].date) = ([130493328.social].date);
Could someone let me know where I'm going wrong?
Thanks
Try writing this with table aliases:
SELECT ga.date, ga.total.visits, s.engagedUsers
FROM [130493328.ga_sessions_20170312] ga LEFT OUTER JOIN
[130493328.social] s
ON ga.date = s.date;
You should also check if you are using Legacy SQL or Standard SQL. The square braces would not be appropriate in Standard SQL.

SQL syntax error using joins

Hoping I can get some help with my SQL syntax. I haven't been able to fix the problem on my own. I used a syntax checker which it says my code is good but I'm getting an error. Any help is greatly appreciated!
SELECT DATALIVE.CO_ALLOCATION_TAIL.PO_KEY,
DATALIVE.CO_ALLOCATION_TAIL.SO_KEY,
DATALIVE.CO_PICK_LOTS_DETAIL.SO_KEY,
Sum(DATALIVE.CO_ALLOCATION_TAIL.QTY_ALLOC) AS SumOfQTY_ALLOC,
Sum(DATALIVE.CO_ALLOCATION_TAIL.PO_ALLOC_QTY) AS SumOfPO_ALLOC_QTY,
Sum(DATALIVE.CO_PICK_LOTS_DETAIL.QTY) AS Picked_Qty,
Min(DATALIVE.CO_ALLOCATION_TAIL.ALLOC_DATE) AS MinOfALLOC_DATE,
Max(DATALIVE.CO_ALLOCATION_TAIL.ALLOC_DATE) AS MaxOfALLOC_DATE,
DATALIVE.CO_SORDER.STATUS
FROM (DATALIVE.CO_ALLOCATION_TAIL
INNER JOIN DATALIVE.CO_SORDER.SO_KEY
ON DATALIVE.CO_ALLOCATION_TAIL.SO_KEY = DATALIVE.CO_SORDER.SO_KEY)
INNER JOIN DATALIVE.CO_PICK_LOTS_DETAIL
ON DATALIVE.CO_ALLOCATION_TAIL.SO_KEY = DATALIVE.CO_PICK_LOTS_DETAIL.SO_KEY
GROUP BY DATALIVE.CO_ALLOCATION_TAIL.PO_KEY,
DATALIVE.CO_ALLOCATION_TAIL.SO_KEY,
DATALIVE.CO_SORDER.STATUS,
DATALIVE.CO_PICK_LOTS_DETAIL.SO_KEY
HAVING (((DATALIVE.CO_SORDER.STATUS) = 'O'))
INNER JOIN DATALIVE.CO_SORDER.SO_KEY
That's a column, not a table. Needs a table, like DATALIVE.CO_SORDER.

Microsoft Office access has stop working error in sql Query

I tried to merge 3 tables it working fine till adding address column of third table. If i add address column and save or click Data Sheet view suddenly Access table stop working and restarts
This is my code i working as parameter but if i give correct column name it showing error. Help me to complete my task.
SELECT RPT_Invoice_Less.InvoiceNumber, RPT_Invoice_Less.Terms,
RPT_Invoice_Less.Invoicedate, RPT_Invoice_Less.OurQuote,
RPT_Invoice_Less.SalesPerson, RPT_Customer.CustomerName,
RPT_Customer.CustomerId, RPT_Customer.ContactPerson,
RPT_Customer.BillingAddress, RPT_Customer.DeliveryAddress,
RPT_Invoice_Less.OrderNumber, RPT_Invoice_Less.ShippingBy,
RPT_Invoice_Less.ShipReferenceNo, RPT_Invoice_Less.Notes,
RPT_Invoice_Less.Price, RPT_Invoice_Less.Discount, RPT_Invoice_Less.Shipping,
RPT_Invoice_Less.Tax, RPT_Invoice_Less.GrandTotal, RPT_OrionSystem.CompanyName,
RPT_OrionSystem.CompanyId, RPT_OrionSystem.RegistrationNumber,
RPT_OrionSystem.Address1, RPT_OrionSystem.MobileNumber,
RPT_OrionSystem.FaxNumber, RPT_OrionSystem.CompanyEmail,
RPT_OrionSystem.CompanyWebsite, RPT_OrionSystem.VatTinNumber
FROM (RPT_Invoice_Less
INNER JOIN RPT_Customer ON RPT_Invoice_Less.CustomerId=RPT_Customer.CustomerId)
INNER JOIN RPT_OrionSystem ON RPT_Invoice_Less.CompanyId=RPT_OrionSystem.CompanyId;
In the 10th line RPT_OrionSystem.Address1 is parameter if I give correct column name RPT_OrionSystem.Address MS Access stop working.
Thanks you guys finally I solved myself by removing sub-queries and join sub-queries directly to this query. This code I used
SELECT RPT_Invoice_Less.InvoiceNumber, RPT_Invoice_Less.Terms, RPT_Invoice_Less.Invoicedate, RPT_Invoice_Less.OurQuote, RPT_Invoice_Less.SalesPerson,
RPT_Customer.CustomerName, RPT_Customer.CustomerId, RPT_Customer.ContactPerson, RPT_Customer_Address.BillingAddress, RPT_Customer_Address.DeliveryAddress,
RPT_Invoice_Less.OrderNumber, RPT_Invoice_Less.ShippingBy, RPT_Invoice_Less.ShipReferenceNo, RPT_Invoice_Less.Notes, RPT_Invoice_Less.Price, RPT_Invoice_Less.Discount, RPT_Invoice_Less.Shipping, RPT_Invoice_Less.Tax, RPT_Invoice_Less.GrandTotal,
RPT_Company.CompanyName, RPT_Company.CompanyId, RPT_Company.RegistrationNumber, RPT_Company_Address.Address, RPT_Company.MobileNumber, RPT_Company.FaxNumber, RPT_Company.CompanyEmail, RPT_Company.CompanyWebsite, RPT_Company.VatTinNumber
FROM (((RPT_Invoice_Less
INNER JOIN RPT_Customer
ON RPT_Invoice_Less.CustomerId=RPT_Customer.CustomerId)
INNER JOIN RPT_Company
ON RPT_Invoice_Less.CompanyId=RPT_Company.CompanyId)
INNER JOIN RPT_Company_Address
ON RPT_Invoice_Less.CompanyId=RPT_Company_Address.AddressId)
INNER JOIN RPT_Customer_Address
ON RPT_Invoice_Less.CustomerId=RPT_Customer_Address.CustomerId;