Two nearly identical Access queries, one gives 'Invalid procedure call' - sql

This runs correctly:
select [feature number],
len(mid([feature number],instr([feature number],"."))) > 2 from featuredata
This gives an Invalid procedure call error:
select [feature number] from featuredata
where len(mid([feature number],instr([feature number],"."))) > 2
feature number is a Text field, but even when I prevent non-numeric values from being processed:
select [feature number] from featuredata
where iif(isnumeric([feature number]),
len(mid([feature number],
instr([feature number],"."))) > 2,false)
I still get the Invalid procedure call error. Why am I getting this error?

What happens is this:
If instr([feature number],".") is 0, then you call
mid([feature number], 0) , and this is invalid.
You shouldn't check for isnumeric([feature number]) in your iif, but for
instr([feature number],".") > 0
Edit: Why does the first version run?
While it runs, it should return #Function! for every row where there is no "." in [feature number]. So the error happens here too.

Related

Invalid procedure call error in MS Access Sum

I use the following SQL select query in MS Access to generate result on large input data:
SELECT "1.01" AS Item
,"Name" AS Test
,Count([Item]) AS [Count]
,Sum(IIf([Results] = "Invalid", 1, 0)) AS [# Invalid]
FROM [Test 1-01]
GROUP BY "1.01"
,"Name"
,"Yes";
I got an 'Invalid Procedure call' error. I traced down the part of the query that caused the error is
Sum(IIf([Results]="Invalid",1,0)) AS [# Invalid]
Does anyone have any idea of how to fix this error ?
#Sergery S. You're right. I found the problem was due to one damaged row data. It works fine again after I removed that row. Thahks again.

Error in list of function arguments: '>' not recognized. Unable to parse query text

I have a query like below in sql server, when i use it in the new query window it has no syntax error and it is executed but when i use it in a view and right click on it for changing design, it has below syntax error but any way it is executed and shows records.
Error in list of function arguments: '>' not recognized.
Unable to parse query text.
SELECT tblDocuments.[Project No],
tblDocuments.Originator,
tblDocuments.Zone,
tblDocuments.Unit,
tblDocuments.Discipline,
tblDiscipline.DiscDesc,
tblDocuments.[Document Type],
tblDocuments.[Owner Document Number],
tblDocuments.[Sazeh Document Number],
tblDocuments.[IDENTIFICATION CODE1],
tblDocuments.[IDENTIFICATION CODE2],
tblDocuments.[Document Title],
tblDocuments.SheetNumber,
CHARINDEX('(', [tblTransmittals].[Owner Document Number]) - 1 AS Doc_Visual_pos,
IIF(CHARINDEX('(', [tblTransmittals].[Owner Document Number]) - 1 > 0, LEFT([tblTransmittals].[Owner Document Number], CHARINDEX('(', [tblTransmittals].[Owner Document Number]) - 1), [tblTransmittals].[Owner Document Number]) AS Doc_Visual,
tblTransmittals.REV,
tblTransmittals.POI,
tblPurposeofIssue.[Purpose of Issue Description],
tblTransmittals.CC,
tblTransmittals.[Int-Tr-NO],
tblTransmittals.[To-Owner-Tr-No],
tblTransmittals.[MC-CSheet-No],
tblTransmittals.AcCode,
tblTransmittals.Pages,
tblTransmittals.PaperSize,
tblTransmittals.SJC_TO_MC_Let_NO,
tblTransmittals.MC_TO_SJC_Let_No,
tblTransmittals.To_FEng_Tr_No,
tblTransmittals.SJC_Tr_No,
tblTransmittals.Ext_Int,
tblTransmittals.[Early Planned Issue Date],
tblTransmittals.[Late Planned Issue Date],
tblTransmittals.[Tag-No],
tblTransmittals.Phase,
tblTransmittals.SubPhase,
tblTransmittals.ActivityID,
tblTransmittals.Manhour,
tblTransmittals.WorkPackage,
tblTransmittals.[DCN-No],
tblTransmittals.[DCR-No],
tblTransmittals.[DCR-Reason],
tblTransmittals.Remark,
tblTransmittals.LastRevPerDoc,
tblTransmittals.LastRevPerPOI,
tblTransmittals.HoldBy,
tblTransmittals.CommentID,
tblTransmittals.ExTrID,
tblTransmittals.HT_TR_No,
tblTransmittals.Recipients,
tblTransmittals.MC_HD_Comment_No,
tblTransmittals.[CT- Transmittals],
tb_CT_CS_transmittalNo.[CT_CS_Tr-Date],
tblTransmittals.DefaultForDocument,
tblTransmittals.HyperDoc,
tblTransmittals.root
FROM tb_CT_CS_transmittalNo
RIGHT JOIN(((tblDocuments
LEFT JOIN tblTransmittals ON tblDocuments.[Owner Document Number] = tblTransmittals.[Owner Document Number])
LEFT JOIN tblPurposeofIssue ON tblTransmittals.POI = tblPurposeofIssue.[Purpose of Issue])
LEFT JOIN tblDiscipline ON tblDocuments.Discipline = tblDiscipline.DiscCode)ON tb_CT_CS_transmittalNo.CT_CS_Tr_No = tblTransmittals.[CT- Transmittals]
WHERE tblTransmittals.Remark_Doc <> 'Deleted'
OR tblTransmittals.Remark_Doc IS NULL;
i would like this does not show this syntax error when i want to change design of view.

Conversion failed when converting the nvarchar value 'CIS100 ' to data type int

Can somebody help me? I'm trying to run a count command so it counts all of the students that are in each class number so I'm running this command. Although I'm getting this error.
Conversion failed when converting the nvarchar value 'CIS100 ' to data type int
Here's my SQL Query
USE RMUDB
GO
SELECt *
FROM Class
WHERE [Class Number] = (Select Count([Class Number]) FROM Enrollment)
If you want to count the students in each class, doesn't the following query do what you want?
SELECT c.[Class Number], COUNT(e.[Class Number])
FROM Class c LEFT JOIN
Enrollment e
ON c.[Class Number] = e.[Class Number]
GROUP BY c.[Class Number];
Your query is comparing the result of a counting operation (an integer) to [Class Number], which is the name of something. It is unlikely that = makes sense.

Syntax Error (missinng operator) in Query expression

I am attempting in Access to show some data in a listbox, but only data which meets a certain condition should be displayed, however my SQL is flagging the error;
Syntax Error (missing operator) in query expression tblItem.[Status] WHERE (tblItem.[Status] = 'Unassigned
Here is my full query
`SELECT tblItem.[Serial Number],
tblItem.[Item Description],
tblItem.[Model],
tblItem.[Status]
WHERE (tblItem.[Status] = 'Unassigned') FROM tblItem;`
Where am i going wrong?
try this
SELECT tblItem.[Serial Number],
tblItem.[Item Description],
tblItem.[Model],
tblItem.[Status]
FROM tblItem
WHERE tblItem.[Status] = 'Unassigned'
I think You have misplaced the from and where clause
Remember the syntax for select:
SELECT ... FROM ... WHERE ... ORDER BY

access sql query aggregate function

I m trying to run a sql in access 2007 which gives the error
"you tried to execute a query that does not include the specified expression 'round(volumePass/Volume*100,2)' as part of an aggregate function".
Whereas i have mentioned it in the sql statement
group by round(volumePass/Volume*100,2)
SELECT s.[sub process name], Round(Avg(s.[TollGate FTEs]),2) AS TollGateFTEs,
Sum(w.volume) AS Volume,
Sum(Switch(w.TAT='Pass',w.Volume,w.TAT='Fail',0)) AS VolumePass,
Sum(IIf(w.[combined accuracy]='PASS',1,0)) AS AccuracyPass,
Sum(IIf(w.[combined accuracy]='',0,1)) AS TotalAccuracy,
Round((VolumePass/Volume)*100,2) AS TATPercentage,
Round((AccuracyPass/TotalAccuracy)*100,2) AS AccuracyPercentage,
Format(w.[reporting month],'mmm-yy') AS [Rep Month] FROM Work_Log1 AS w,
[sub process] AS s WHERE w.[sub process] In (SELECT s.[sub_process_id] FROM
[Sub Process] s,
[process mapping] m where m.[process name] like 'Accounting Control%'
and s.[mapped to process id] = m.[mapping id]) And w.[sub process]=[s].[sub_process_id]
AND (w.[Activity_start_date] Between #06/01/2012# And #06/15/2012#)
AND ([w].[sla applicable]=1 Or 0 Or '') and
(w.[status] Like 'Complete%') group BY Format(w.[reporting month],'mmm-yy'),
s.[sub process name], (Round((VolumePass/Volume)*100,2));
Where is that it is not able to pick up correctly.
giving the alias "TATPercentage" still not works and gives the same error.
This query works well in access query designer but cannot be run with sql inside vba.
Update:
Got it to run using the dao engine in vba.. no luck with adodb engine
Round((VolumePass/Volume)*100,2) AS TATPercentage
^^^^^^^^^^ ^^^^^^
round() is not an aggregate function. You'll have to group on those fields as well (volumepass and volume), and you'll run into the same error with your next two lines with accuracypass, acuracytotal, reporting month, etc...