Microsoft Office access has stop working error in sql Query - sql

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;

Related

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!

SQL Query - MS SCCM

I´m trying to make a report in MS SCCM where I can check the distribution status of Software XY. Now there can be more parts of one software installed (for example XYa, XYb....) but I only want to list the pc once in my report.
I tried this adding the keyword distinct but nothing changes. Can you help me?
Here´s my query:
select distinct SMS_R_System.Name0,__System_ADD_REMOVE_PROGRAMS0.DisplayName00,__System_ADD_REMOVE_PROGRAMS0.Version00 from vSMS_R_System AS SMS_R_System INNER JOIN Add_Remove_Programs_DATA AS __System_ADD_REMOVE_PROGRAMS0 ON __System_ADD_REMOVE_PROGRAMS0.MachineID = SMS_R_System.ItemKey INNER JOIN _RES_COLL_SMS00001 AS SMS_CM_RES_COLL_SMS00001 ON SMS_CM_RES_COLL_SMS00001.MachineID = SMS_R_System.ItemKey where __System_ADD_REMOVE_PROGRAMS0.DisplayName00 like N'%XY%'
You'll get a row returned for each different application name and version because you're including DisplayName00 and Version00 in your SELECT statement. If you just have the system name in the SELECT then the distinct will work as intended.

Access SQL query without duplicate results

I made a query and wanted to not have any duplicates but i got some times 3 duplicates and when i used DISTINCT or DISTINCTROW i got only 2 duplicates.
SELECT f.flight_code,
f.status,
a.airport_name,
a1.airport_name,
f.departing_date+f.departing_time AS SupposedDepartingTime,
f.landing_date+f.landing_time AS SupposedLandingTime,
de.actual_takeoff_date+de.actual_takeoff_time AS ActualDepartingTime,
SupposedLandingTime+(ActualDepartingTime-SupposedDepartingTime) AS ActualLandingTime
FROM
(((Flights AS f
LEFT JOIN Aireports AS a
ON a.airport_code = f.depart_ap)
LEFT JOIN Aireports AS a1
ON f.target_ap = a1.airport_code)
LEFT JOIN Irregular_Events AS ie
ON f.flight_code = ie.flight_code)
LEFT JOIN Delay_Event AS de
ON ie.IE_code = de.delay_code;
had to use LEFT JOIN because when i used INNER JOIN i missed some of the things i wanted to show because i wanted to see all the flights and not only the flights that got delayed or canceled.
This is the results when i used INNER JOIN, you can see only the flights that have the status "ביטול" or "עיכוב" and that is not what i wanted.
[the results with LEFT JOIN][2]
[2]: https://i.stack.imgur.com/cgE2G.png
and when i used DISTINCT where you see the rows with the NUMBER 6 on the first column it appear only two times
IMPORTANT!
I just checked my query and all the tables i use there and i saw my problem but dont know how to fix it!
in the table Irregular_Events i have more the one event for flights 3,6 and 8 and that is why when i use LEFT JOIN i see more even thou i use distinct, please give me some help!
Not entirely sure without seeing the table structure, but this might work:
SELECT f.flight_code,
f.status,
a.airport_name,
a1.airport_name,
f.departing_date+f.departing_time AS SupposedDepartingTime,
f.landing_date+f.landing_time AS SupposedLandingTime,
de.actual_takeoff_date+de.actual_takeoff_time AS ActualDepartingTime,
SupposedLandingTime+(ActualDepartingTime-SupposedDepartingTime) AS ActualLandingTime
FROM
((Flights AS f
LEFT JOIN Aireports AS a
ON a.airport_code = f.depart_ap)
LEFT JOIN Aireports AS a1
ON f.target_ap = a1.airport_code)
LEFT JOIN
(
SELECT
ie.flight_code,
de1.actual_takeoff_date,
de1.actual_takeoff_time
FROM
Irregular_Events ie
INNER JOIN Event AS de1
ON ie.IE_code = de1.delay_code
) AS de
ON f.flight_code = de.flight_code
It is hard to tell what is the problem with your query without any sample of the output, and without any description of the structure of your tables.
But your problem is that your are querying from the flights table, which [I assume] can be linked to multiple irregular_events, which can possibly also be linked to multiple delay_event.
If you want to get only one row per flight, you need to make sure your joins return only one row too. Maybe you can do it by adding one more condition to the join, or by adding a condition in a sub-query.
EDIT
You could try to add a GROUP BY to the query:
GROUP BY
f.flight_code,
f.status,
a.airport_name,
a1.airport_name;

Query is too complex error in ms access?

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.

How to create a query to get all records from one table and fill in field information from a second table with a where statement?

I have two tables. One is called prem and contains all ids that exist in a system, and JimsQueryByColl which has most of those ids with various information attached. I am trying to create a single query that will include all of the ids from prem, and all of the records from the JimsQueryByColl where JimsQueryByColl.Collector = "Frederick Road". The current query I have is as follows but only gives the latter part of the information (without the ids from the prem that don't appear in a list of ids with Frederick Road in the collector collumn):
SELECT Prem.meter_miu_id,
JimsQueryByColl.*, Prem.longitude,
Prem.latitude
FROM Prem LEFT JOIN
JimsQueryByColl ON Prem.meter_miu_id =
JimsQueryByColl.[MIU ID]
WHERE
(((JimsQueryByColl.Collector)="Frederick
Road"))
Normally the Left Join would have achieved what i desire but the where statement is making it where the ids that would have blank information for all but the *Prem.meter_miu_id* field are not included. I have tried to add an "or JimsQueryByColl.Collector IS NULL" to the WHERE statement but that didn't get the correct result.
The current two query method I have for getting the right information are titled FredrickRoad and Query3:
FredrickRoad-
SELECT JimsQueryByColl.* FROM
JimsQueryByColl WHERE
(((JimsQueryByColl.Collector)="Frederick
Road"))
Followed by Query3 -
SELECT Prem.meter_miu_id,
JimsQueryByColl.*, Prem.longitude,
Prem.latitude FROM Prem LEFT JOIN
JimsQueryByColl ON Prem.meter_miu_id =
JimsQueryByColl.[MIU ID] WHERE
(((JimsQueryByColl.Collector)="Frederick
Road"));
But I would like to do this in one step if possible. I hope I have written this clearly and if someone needs clarification just ask.
Current Solution
SELECT Prem.meter_miu_id,
JimsQueryByColl.*, Prem.longitude,
Prem.latitude
Into FrederickRoad
FROM Prem LEFT JOIN
JimsQueryByColl ON (Prem.meter_miu_id
= JimsQueryByColl.[MIU ID]
AND JimsQueryByColl.Collector="Frederick
Road")
This gets around the odd bug/error I'm getting with the query since it puts it into a table and doesn't deal with the query directly again. I would however love to know what is causing the problems I'm having.
Try:
SELECT Prem.meter_miu_id, JimsQueryByColl.*, Prem.longitude, Prem.latitude
FROM Prem LEFT JOIN JimsQueryByColl
ON (Prem.meter_miu_id = JimsQueryByColl.[MIU ID]
AND JimsQueryByColl.Collector="Frederick Road")