Microsoft Access won't show query if date is empty? - sql

--SOLVED--
I'm having a problem with a query in Microsoft Access.
I need this query to show a list of entries where a specific Date field is empty. So it must sort and still show all the data, but only for entries where that specific date is missing.
There are a lot of dates in the table.
When I create a filter or just add criteria to the specific field in "Design View", it runs the query but it's empty without fail every time.
The field format is naturally a "Date" type field in the table.
I hope anyone can help me.
Thank you.
SQL BELOW:
SELECT rptClaimDateEmpty.Claim_Date, *
FROM (SELECT tblContainers.*, tbluCommodities.Commodity,
tbluContainerSizes.ContainerSize, tbluCountryOfLoading.CountryOfLoading,
tbluCountryOfOrigin.CountryOfOrigin, tbluShippers.Shipper,
tbluShippingLines.ShippingLine, tbluPortOfLoading.PortOfLoading,
tblBOLDates.BOLNumber FROM tblBOLDates INNER JOIN (tbluPortOfLoading RIGHT
JOIN (tbluShippingLines RIGHT JOIN (tbluShippers RIGHT JOIN
(tbluCountryOfOrigin RIGHT JOIN (tbluCountryOfLoading RIGHT JOIN
(tbluContainerSizes RIGHT JOIN (tbluCommodities RIGHT JOIN tblContainers ON
tbluCommodities.CommodityID = tblContainers.CommodityID) ON
tbluContainerSizes.ContainerSizeID = tblContainers.Container_SizeID) ON
tbluCountryOfLoading.CountryOfLoadingID =
tblContainers.Country_of_LoadingID) ON tbluCountryOfOrigin.CountryOfOriginID
= tblContainers.Country_of_OriginID) ON tbluShippers.ShipperID =
tblContainers.ShipperID) ON tbluShippingLines.ShippingLineID =
tblContainers.Shipping_LineID) ON tbluPortOfLoading.PortOfLoadingID =
tblContainers.Port_of_LoadingID) ON tblBOLDates.BOLDateID =
tblContainers.BOLDateID) AS rptClaimDateEmpty;
I just need it to sort via the the "Claim Date" field where "Claim Date" is empty.

Wouldn't it just be:
SELECT *
FROM (...) AS rptClaimDateEmpty
WHERE rptClaimDateEmpty.Claim_Date Is Null;

Related

display the same column twice with different results

I have a column that contains Enable and Disable values, which is associated by an event id, in this event table I have the user datatime, I would like to create a query and display the time the enabled event was triggered and in the same row. the time the disable was triggered
SELECT
valv.valvOf, valv.cam,
cod.descOf Habilita, cod.descof Desabilita
FROM
{oj (aspersao.dbo.events events LEFT JOIN aspersao.dbo.valv valv ON events.valv_id = valv."id") LEFT JOIN aspersao.dbo.cod cod ON events.cod_id = cod.id}
WHERE
valv.cam = '1'
and
Habilita = 'Habilitou valvula'
and
Desabilita = 'Desabilitou valvula'
Even after correcting your code so that you are not trying to refer to columns by their aliases in the WHERE clause, your code is nonsense. No row will have a column equal to two different values.
Likely you want to pull in the table twice. I'm also getting rid of the ODBC specific curly brace syntax.
SELECT
valv.valvOf, valv.cam,
cod1.descOf AS Habilita, cod2.descof AS Desabilita
FROM
aspersao.dbo.events AS events
LEFT JOIN aspersao.dbo.valv AS valv ON events.valv_id = valv."id"
LEFT JOIN aspersao.dbo.cod AS cod1
ON events.cod_id = cod1.id
AND cod1.descOf = 'Habilitou valvula'
LEFT JOIN aspersao.dbo.cod AS cod2
ON events.cod_id = cod2.id
AND cod2.descOf = 'Desabilitou valvula'
WHERE
valv.cam = '1'
This is pretty much a guess because there really isn't enough info in your question.
EDIT: I had the wrong test string in the cod2.descOf = line; I've fixed that.

OracleAPPS- Can not get correct results for Suppliers - Bank query

I am trying to fetch suppliers and bank details in Oracle apps. I am able to write a simple query where each supplier has a supplier site attached to it. Few of my sites doesn't have a record in table "iby_pmt_instr_uses_all". But even then I want to show them . So I am using the outer join on this table. But the issue is when I am putting this outer join condition, I am getting double the records in the query. I believe I am missing on some condition, but can not figure out which one.
SELECT *
FROM apps.iby_pmt_instr_uses_all instrument,
apps.iby_account_owners owners,
apps.iby_external_payees_all payees,
apps.iby_ext_bank_accounts ieb,
apps.ap_supplier_sites_all asa,
apps.ap_suppliers asp,
apps.ce_bank_branches_v cbbv
WHERE owners.ext_bank_account_id = ieb.ext_bank_account_id
AND owners.ext_bank_account_id = instrument.instrument_id(+)
AND payees.ext_payee_id = instrument.ext_pmt_party_id(+)
AND cbbv.branch_party_id = ieb.branch_id
AND payees.payee_party_id = owners.account_owner_party_id
AND payees.supplier_site_id = asa.vendor_site_id
AND asa.vendor_id = asp.vendor_id
AND asp.vendor_name = 'PANALYTICAL'
--and ieb.bank_account_num = asa.VENDOR_SITE_CODE
If I add and ieb.bank_account_num = asa.VENDOR_SITE_CODE this condition I get the correct record, but actually this is not the right join, because there is no relationship between these 2 columns, so this will fail for other suppliers.
Can you please suggest what additional join I can put , so that I get the right result.
Thanks

Microsoft Access 2016: Conditional Inner Join Multiple Cases

I hope what I'm asking for makes sense. I would like to have a query that chooses a specific type of Inner Join based on a user input.
This is what I have.
Queries:
qryFiltered (Main Query)
qryLand (sub)
qrySea (sub)
qryAllOrder (sub)
Tables:
tblLowPriority
Forms:
EnterWork (which has a option group called ogLandSea)
In my main query "qryFiltered", I have the following SQL code:
SELECT qryAllOrder.*
FROM
SWITCH
(Forms!EnterWork!ogLandSea = 1, (qryAllOrder LEFT JOIN tblLowPriority ON qryAllOrder.[WORK_ORDER_NBR] = tblLowPriority.[WO]) INNER JOIN qrySea ON qryAllOrder.WORK_ORDER_NBR = qrySea.WORK_ORDER_NBR,
Forms!EnterWork!ogLandSea = 2, (qryAllOrder LEFT JOIN tblLowPriority ON qryAllOrder.[WORK_ORDER_NBR] = tblLowPriority.[WO]) INNER JOIN qryLand ON qryAllOrder.WORK_ORDER_NBR = qryLand.WORK_ORDER_NBR)
WHERE tblLowPriority.WO Is Null
Basically, what I'm looking for is to choose the join based on what the user selects on the form. The inner join would choose either qrySea or qryLand based on this input. The error I'm getting is: "Syntax error in FROM clause."
What am I doing wrong here? It's the Switch function that's not working. I tried the two Land and Sea options separately without the Switch function and it works. I just can't seem to figure out a way to have the Inner Join change based on user input.
Appreciate all your responses!
I was able to get this to work by doing a Left Join from the main query to the two subqueries. And then I put a Switch criteria in the WHERE Clause:
WHERE (Switch([Forms]![EnterWork]![ogLandSea]=1,[qrySea]![WORK_ORDER_NBR] Is Not Null Or [qrySea]![WORK_ORDER_NBR] Is Null Or [qryLand]![WORK_ORDER_NBR] Is Not Null,[Forms]![EnterWork]![ogLandSea]=2,[qrySea]![WORK_ORDER_NBR] Is Not Null,[Forms]![EnterWork]![ogLandSea]=3,[qryLand]![WORK_ORDER_NBR] Is Not Null,[Forms]![EnterWork]![ogFN]=4,[qrySea]![WORK_ORDER_NBR] Is Null And [qryLand]![WORK_ORDER_NBR] Is Null))<>False)
Basically, this is what it does:
Option 1: Display all records from the Main Query
Option 2: Display only records that are in qrySea
Option 3: Display only records that are in qryLand
Option 4: Display only records that are NOT in qrySea nor qryLand

Long Text Field over 255 Characters gets truncated

Not sure why my field in my query is getting truncated upon the return of the result. The value is being stored in the field, but gets truncated by access to help with "performance". I have reviewed multiple forums and SO posts to no avail.
Problems listed at link do not apply, Aggregation, Uniqueness, Union, Format Property, Row Source
What is wrong with my query? Instructions field in the Customer table is the one that is getting truncated.
Here is the raw query generated by access:
SELECT Task.ID, Task.TaskID, Task.TaskName, Task.TypeID, TaskType.TaskTypeName, Task.CustomerID, Customer.CustomerName, Customer.OnHold, Customer.Blacklisted, Customer.CustomerEngagementRecieved, Customer.AutoEmail, Customer.SpecialInstructions, Customer.Instructions, Task.QuoteRequired, Task.PriorityID, Priority.Priority, Task.Min, Task.Max, Task.Projected, Task.DeadlineDate, Task.ResourceID, Resource.ResourceName, Resource.Email, Resource.Extension, Task.Description, Task.StatusID, Status.Status, Task.DeveloperLog, Task.TaskPOCID, POC.Phone, POC.Email, Task.OtherPOC, Task.OtherPOCPhone, Task.OtherPOCEmail, Task.FolderPath, Task.StopBilling, Task.Premium, Task.EntryDate, Task.CompleteDate, Task.AssignedBy, Task.SettingsID, Settings.AutoEmail
FROM TaskType
INNER JOIN (Status
INNER JOIN (Settings
INNER JOIN (Resource
INNER JOIN (Priority
INNER JOIN (Customer
INNER JOIN (Task
INNER JOIN POC ON Task.TaskPOCID = POC.POCID)
ON Customer.CustID = Task.CustomerID)
ON Priority.PriorityID = Task.PriorityID)
ON Resource.ResourceID = Task.ResourceID)
ON Settings.SettingsID = Task.SettingsID)
ON Status.StatusID = Task.StatusID)
ON TaskType.TTID = Task.TypeID;
`
Have a close read of this - http://allenbrowne.com/ser-63.html something in your set up will causing the truncation.
If it's when you cut and paste the query results that can also be mis-leading. When you say a Long Text are these linked tables?
I'd also rename your Min and Max fields as they are reserved words and may cause access to think you are aggregating your data.
So from the sounds of it, Access just sometimes will ALWAYS truncate the field no matter what the settings. There is a way to force access to show the entire field though, by using the DLOOKUP() function instead of using a Control Source.
Here is the Answer to my current Issue for reference,
=DLOOKUP("Instructions", "Customer", "CustID=" & [CustomerID])

MS Access SQL Update with Minimum

This SQL is beyond my expertise. I think it should be fairly easy for someone with experience. Here is what I have so far..
SQL is as follows:
UPDATE (Tbl_Stg_Project_Schedule_Dates
INNER JOIN Tbl_Child_ITN ON Tbl_Stg_Project_Schedule_Dates.ms_itn = Tbl_Child_ITN.ITN)
INNER JOIN Tbl_Schedule ON Tbl_Child_ITN.Id = Tbl_Schedule.ID SET Tbl_Schedule.a_construction_start = [Tbl_Stg_Project_Schedule_Dates].[ms_start_date]
WHERE (((Tbl_Stg_Project_Schedule_Dates.ms_tempt_id) In (16,17,18,19,20,21,22,23)));
I want to add one last condition to this being that I only want the minimum of [Tbl_Stg_Project_Schedule_Dates].[ms_start_date] to update the table. I've tried the obvious of wrapping the field in Min, and also tried creating a separate aggregate select statement first (to get the min value with other criteria) that I then tried to create the update query from in new query but no luck.
I believe this is valid Access/Jet SQL. The idea here is to use a subquery to look up the earliest date among all the rows in your subset. I'm not sure if ms_itn was the right column to correlate on but hopefully you get the idea:
UPDATE (Tbl_Stg_Project_Schedule_Dates
INNER JOIN Tbl_Child_ITN ON Tbl_Stg_Project_Schedule_Dates.ms_itn = Tbl_Child_ITN.ITN)
INNER JOIN Tbl_Schedule ON Tbl_Child_ITN.Id = Tbl_Schedule.ID
SET Tbl_Schedule.a_construction_start = [Tbl_Stg_Project_Schedule_Dates].[ms_start_date]
WHERE (((Tbl_Stg_Project_Schedule_Dates.ms_tempt_id) In (16,17,18,19,20,21,22,23)))
and [Tbl_Stg_Project_Schedule_Dates].[ms_start_date] = (
select min(sd.[ms_start_date])
from [Tbl_Stg_Project_Schedule_Dates] as sd
where sd.ms_itn = [Tbl_Stg_Project_Schedule_Dates].ms_itn
)