Microsoft Access Error - ms-access

Error: Invalid use of IS operator in query expression...
Here is the formatted SQL-Code by poorsql.com
TRANSFORM Sum(Jacksonville.[Lease Rent]) AS SumOfAmount
SELECT S.Unit
,S.[Floorplan]
,S.[Unit Designation]
,S.SQFT
,S.[Unit and Lease Status]
,S.NAME
,S.[Move-In and Move-Out]
,S.[Lease Start]
,S.[Lease End]
,S.[Market and Addl.]
,S.[Sub Journal]
,S.[Trans Code]
,S.[Lease Rent]
,S.[Charges and Credits]
FROM Jacksonville
,(
SELECT Q.Id
,Val(DMax(“Id”, ”Jacksonville”, ”Id <= “ & Q.[Id] & “
AND Unit IS NOT Null”)) AS ParentId
FROM Jacksonville AS Q
) AS T
,(
SELECT Jacksonville.Id
,Jacksonville.Unit
,Jacksonville.[Floorplan]
,Jacksonville.[Unit Designation]
,Jacksonville.SQFT
,Jacksonville.[Unit and Lease Status]
,Jacksonville.NAME
,Jacksonville.[MoveIn and MoveOut]
,Jacksonville.[Lease Start]
,Jacksonville.[Lease End]
,Jacksonville.[Market and Addl]
,Jacksonville.[Sub Journal]
,Jacksonville.[Trans Code]
,Jacksonville.[Lease Rent]
,Jacksonville.[Charges and Credits]
FROM Jacksonville
WHERE Jacksonville.Unit IS NOT NULL
) AS S
WHERE Jacksonville.Id = [T].[Id]
AND T.ParentId = [S].[Id]
GROUP BY T.ParentId
,S.Unit
,S.[Floorplan]
,S.[Unit Designation]
,S.SQFT
,S.[Unit and Lease Status]
,S.NAME
,S.[Move-In and Move-Out]
,S.[Lease Start]
,S.[Lease End]
,S.[Market and Addl.]
,S.[Sub Journal]
,S.[Trans Code]
,S.[Lease Rent]
,S.[Charges and Credits]
PIVOT Jacksonville.[Trans Code] IN (
[“ADMIN HOUS”]
,”EXRENT”
,[”LHA RENT”]
,[”MK-PREMIUM LHA”]
,”RENT”
,”SUBRENT”
,”SUBSIDY”
,”UTAC”
,”UTILREIMB”
,”OFF / SOCIAL”
);
This syntax works on my other one, but not here for some reason. Why is my IS statement wrong?
Not sure how to edit the query structure on here.

Replace the "smart quotes" (from a copy-paste from Word?) with double-quotes:
,Val(DMax("Id", "Jacksonville", "Id <= " & Q.[Id] & "
AND Unit IS NOT Null")) AS ParentId

Related

VB Function giving errors- Syntax error missing operator in query expression '[!D]'=123 AND [POID] = & MfrOrderID & (3075) –

Im trying to get the values of raw material required to fulfill a production order, product recipe is stored in another table with required quantities im using this simple function to get the values from query
Function GetRMWt(ProductID) As Long
GetRMWt = DLookupNumberWrapper("[RM Req]", "RMCalc", "[ID]=" & ProductID & " AND [POID] = & MfrOrderID &")
End Function
and calling this function to get the values
Private Sub Product_ID_AfterUpdate()
If Not IsNull(Me![Product ID]) Then
Me![Quantity] = GetRMWt(Me![Product ID])
Me.Quantity.Locked = False
Me![Unit Price] = GetListPrice(Me![Product ID])
Me![Discount] = 0
Me![Status ID] = None_OrderItemStatus
Else
eh.TryToRunCommand acCmdDeleteRecord
End If
End Sub
This is the query that fetches the required data
SELECT Products.ID
,ProductReceipe.PID
,ProductReceipe.[Product ID]
,[Mfr Order Details].Quantity AS [Item Qty]
,ProductReceipe.Quantity AS [RM Qty]
,([Item Qty] * [RM Qty] / 1000) AS [RM Req]
,[Mfr Order Details].[Mfr Order ID] AS POID
,IGROrders.[IGR Order ID]
FROM ProductReceipe
,[Mfr Order Details]
,[Mfr Orders]
,IGROrders
,Products
WHERE ProductReceipe.PID ) = [Mfr Order Details].[Product ID]
AND [Mfr Orders].[Mfr Order ID] = [Mfr Order Details].[Mfr Order ID]
AND [Mfr Orders].[Mfr Order ID] = [IGROrders].[Mfr Order ID]
AND Products.ID = ProductReceipe.[Product ID]

SQL Subquery issue 3

I have a issue with my SQL code.
When I run this code I'm getting such error mesage:
**
Subquery returned more than 1 value. This is not permitted when the
subquery follows =, !=, <, <= , >, >= or when the subquery is used as
an expression.
**
I don't know how to correct this code to run it?
Can somebothy look at it and help me with it?
Thank you for your help,
SELECT dbo.FRA$.[GUID], dbo.FRA$.[Last Name],
dbo.FRA$.[First Name], dbo.FRA$.[HR Manager Last Name],
dbo.FRA$.[HR Manager First Name], (SELECT dbo.FRA$.[Business Email Address] FROM dbo.FRA$ t WHERE t.[HR Manager ID] = t.[Emplid]) AS [HR Manager E-Mail],
dbo.LOC.Descr AS [COMPANY NAME], dbo.FRA$.[Location Code],
dbo.LOC.[ADDRESS], dbo.LOC.Postal, dbo.LOC.City, dbo.FRA$.[National ID], dbo.FRA$.[Current Employee Class Desc] AS [Current Empl Class],
dbo.FRA$.[Contract type description] AS [CONTRACT TYPE], dbo.FRA$.[Business Title],
CASE dbo.FRA$.[Current Employee Class Desc]
WHEN 'Operator' THEN 10
WHEN 'Clerical worker' THEN 22
WHEN 'Technician' THEN 32
WHEN 'Supervisor' THEN 33
WHEN 'Manager&Engineer' THEN 54
END AS [Salary brutto],
FORMAT(dbo.FRA$.[Birthdate],'yyyy-MM-dd') AS [Birth Date], FORMAT(dbo.FRA$.[Last Start Date],'yyyy-MM-dd') AS [Hire Date]
FROM dbo.FRA$
INNER JOIN dbo.LOC
ON dbo.FRA$.[Location Code] = dbo.LOC.[Location]
WHERE [HR Status] IN ('International Assignment','Active','Leave of Absence');
Try to replace
SELECT dbo.FRA$.[Business Email Address] FROM dbo.FRA$ t WHERE t.[HR Manager ID] = t.[Emplid]
with
SELECT TOP 1 t.[Business Email Address] FROM dbo.FRA$ t WHERE [HR Manager ID] = t.[Emplid]
it will take only one row from rows returned by your subquery

Grouping by same column / variable using two separate imported views and separate calculations

So basically my code involves a created a table which has the LAST COLUMN as the SUM of the previous two columns, with the first of the two coming from table X and the second of the two columns coming from the 'INNER JOIN OF table X with table Y'.
HOWEVER, I want to group ALL THREE of these columns by the 'COUNTERPARTY', a variable which is present BOTH in 'table X' AND in 'INNER JOIN OF TABLE X WITH TABLE Y.'
The tricky part is that there will be some COUNTERPARTIES for which we have data set 1 (coming from TABLE X) and some COUNTERPARTIES for which we have data set 2 (coming from INNER JOIN OF table X with table Y) and SOME FOR WHICH WE HAVE BOTH DATASETS! I WANT TO INCLUDE THE INTERSECTION AS WELL AS THE OUTLIERS BUT ONLY AFTER CHECKED AGAINST A MASTER KEY OF COUNTERPARTIES called c.COUNTERPTY.
Please carefully go through the code below to see how the above explanation is relevant to the problem at hand. I apologize for the length of the code.
select
p.Name as ENTITY, t.[Counterparty Code], c.CNTRPTY_DS as COUNTERPARTY, cs.Tier,
... irrelevant code removed
sum((t.[Current value decimal] - t.[Trade price decimal])/100 * case when t.[Buy Sell Code] = 'B'
then 1 else -1 end * t.[Open Amount]) as [OPEN MTM ($)],
sum((t2.[Weighted Average Settled Pair Off Price] - t2.[Trade price decimal])/100 * case when t2.[Buy Sell Code] = 'B'
then 1 else -1 end * ISNULL(PO.[Pairoff Amount],0)) as [Unsettled Pairoffs/ AOTs ($)],
sum((t.[Current value decimal] - t.[Trade price decimal])/100 * case when t.[Buy Sell Code] = 'B'
then 1 else -1 end * t.[Open Amount]) + sum((t2.[Weighted Average Settled Pair Off Price] - t2.[Trade price decimal])/100 * case when t2.[Buy Sell Code] = 'B'
then 1 else -1 end * ISNULL(PO.[Pairoff Amount],0)) as [TOTAL MTM Exposure ($)]
from
[la-w08-qrm-db-1].qrmprod.dbo.vw_QRM_Trades t2
inner join
[la-w08-qrm-db-1].qrmprod.dbo.VW_QRM_TRADE_PAIROFFS PO
ON
PO.[In Ticket Number] = t2.[Ticket number]
and PO.[Portfolio ID] = t2.[Portfolio ID]
and t2.[derivative type] = 'F' -- note repeat below
and t2.[forward type] ='MBS'
and t2.[Counterparty Code] not in ('PLS', 'PNCO')
and t2.[Portfolio ID] in (1,7)
and t2.[Settlement date] > GETDATE(),
prod.dbo.vw_QRM_Trades t,
prod.dbo.portdesc p,
prod.dbo.cptyall c,
prod.dbo.VW_MB_ACTIVE_RUN r,
pulsar.dbo.CntrPrtySetup CS,
pulsar.dbo.CntrPrtyTiers CT
where
r.mrktid = 1
And r.asmpid = 1
And r.cyclid = 1
and r.compid = t.[Company ID]
and r.portid = t.[Portfolio ID]
and p.PORTID = t.[Portfolio ID]
and c.COUNTERPTY = t.[Counterparty Code] --key piece of code
and cs.CNTRPTY_NO = c.CNTRPTY_NO
and cs.PortID = t.[Portfolio ID]
and cs.Tier = ct.Tier
and t.[derivative type] = 'F' -- note repeat above
and t.[forward type] ='MBS'
and t.[Counterparty Code] not in ('PLS', 'PNCO')
and t.[Portfolio ID] in (1,7)
and t.[Open Amount] > 0
group by
p.Name, c.CNTRPTY_DS , t.[Counterparty Code], cs.Tier -- yes this
order by
p.Name, c.CNTRPTY_DS , t.[Counterparty Code], cs.Tier -- and this
The way to do is was to actually use UNION in order to join three tables together in the order and given the properties I wanted from each of them. Eventually I did manage to finish the whole stored procedure!

How do I find the last entry in a table, by date

My query keeps returning the last date for ONRENT and CLOSED for the same piece of equipment when I add the column "AVAILABILITY". I only want the last entry for each piece of equipment.
Here is my query:
select max([No_]), [Start Date], [Availability Status]
from [Rental Line]
group by [No_], [Start Date], [Availability Status]
If I'm understanding your question correctly, you want only the last availability status for each piece of equipment defined by No_, where "last" would be defined by the latest start date. If so, this should work:
Try this:
select RL.[No_], RL.[Start Date], RL.[Availability Status]
from [Rental Line] RL
join
(
select
No_,
MAX([Start Date]) AS [LastStartDate]
from [Rental Line] RL1
group by No_
) X on RL.No_ = X.No_ AND RL.[Start Date] = X.[LastStartDate]
select max([No_]), [Start Date], [Availability Status]
from [Rental Line]
group by [No_], [Start Date], [Availability Status]
order by [AVAILABILITY] DESC

display only sql fields having values in asp

i am having a asp web page that retrieves value from sql...it shows the fields without having values..is there anyway to display only the fields having values..this is my table
[] [][] "Mfg Dt and Exp Dt as per Annexure enclosed"
this square brackets contain null values..if the field is empty then this square bracket will not come
in first row i am having 2 sets of square brackets and in second row i am having the values in 2 sets..i need to show only the square bracket having values like in the second row..if the value is empty then dont want to show that empty brackets.
sql query
select I.[Old Product Code], I.[Trade Name], I.[Short Name], SUM(Quantity) as Qty,I.[Base Box UOM], SIH.[Customer Marks - 1] ,SIH.[Bill-to Name],SIH.[Bill-to Address], SIH.[Ship-to Name], SIH.[Ship-to Address], SIH.[Ship-to Address 2] ,SIH.[Ship-to City], SIH.[Ship-to Post Code],SIH.[Country of Origin of Goods],SIH.[Bill-to Address 2] ,SIH.[Bill-to City] , SIH.[Bill-to Post Code], CR.Name ,C.Contact,SIH.[Total Boxes], CASE when SIL.[Dimension Group Code] = 'IOL' then I.[Group Description]
END ,
CASE
when I.[EPCG License] = 1 then 'EPCG'
end,
case
when SIL.[Dimension Group Code] = 'IOL' then 'DEEC'
when I.[DEEC Lic_] = 1 then 'DEEC'
end as abcd
from [Sales Invoice Header] SIH ,[Customer] C, [Country_Region] CR,
[Sales Invoice Line] SIL,[Item] I where I.No_ = SIL.No_ and SIL.[Document No_]='PEXP1213-110' and SIH.No_ = SIL.[Document No_] and C.No_ = SIH.[Bill-to Customer No_] and C.[Country_Region Code] = CR.Code group by I.[Old Product Code], I.[Trade Name], I.[Short Name], SIH.[Sell-to Customer Name],SIH.[Sell-to City],SIH.[Customer Marks - 1],SIL.[Dimension Group Code],I.[Group Description], SIH.[Country of Origin of Goods], SIH.[Ship-to Name],SIH.[Ship-to Address], SIH.[Ship-to Address 2] , SIH.[Ship-to City], SIH.[Ship-to Post Code],SIH.[Bill-to Name],SIH.[Bill-to Address],SIH.[Bill-to Address 2],SIH.[Bill-to City] , SIH.[Bill-to Post Code],SIH.[Total Boxes],C.Contact ,CR.Name,I.[Base Box UOM], I.[EPCG License],I.[DEEC Lic_]
You need to solve it programmatically like
if cstr(rs("Old Product Code"))="[]" then
response.write("")
else
response.write(rs("Old Product Code"))
end if