Access 2010 Query using IIF and ISERROR - sql

I am trying to accomplish the following in an Access 2010 query
Select
UNIT, DATE, Sum(IIF(ISERROR(A),NULL,A)) AS DLP_PERCENTAGE
From
tableA;
where
A = (ACT-BASE)/BASE
I get a generic OVERFLOW error. I am missing something obvious. I am trying to catch an error in the calculation and return NULL if an error exists or the result if no error. I have to do it in a query. Any ideas what I have overlooked?

SUM((ACT-BASE)/IIF(BASE=0, Null, BASE)) AS DLP_PERCENTAGE

Related

(Editied): Error executing query in metabase: (ERROR: syntax error at or near "and" Position: 33)

I am running a very simple query in Metabase, however, I am getting an error.
Following is the code I am running:
SELECT user_id
FROM order_order
[[where date_placed between {{from}} and {{to}}]]
and {{partner_id}}
Following is the error I am getting:
ERROR: syntax error at or near "and" Position: 33
I have been trying multiple ways to get this fixed, but couldn't get this to work. I would appreciate your help with this query. I don't see a problem with the query tho. What am I missing?
Attaching image for refrence
I think you just want:
SELECT user_id
FROM order_order
where
{{partner_id}}
[[and {{date}}]]
then use an advanced date query to do the between part?
All from memory so hope I'm not way off.
The statement inside the [[ ]] in your query is only used when from or to variables have a selected value. That means that when both from and to are not set (no value selected) your query will be the following:
SELECT user_id
FROM order_order
and {{partner_id}}
hence the error.
In order to resolve it you should set the where clause to always true and then have the conditional statements that you want. Here is an example:
SELECT user_id
FROM order_order
where true
[[and date_placed between {{from}} and {{to}}]]
and {{partner_id}}

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.

TOAD 10.6 Sql Error ORA - 01858: What is wrong with query?

Please help me identify the below issue. I have a canned query below and can't get it to run without getting this error:
SELECT * FROM TABLE(fdr_dal_txns.get_txn_trans_adjst_consol
(short_string_col('1BFV')
,'POST_DT'
,short_string_col('MCH','GP3', 'OTC')
,'01-may-2017'
,'30-june-2017'
))
WHERE trd_id_num IN ('17FHKBBSSML',
'17FHVBBRJD8')
What is obvious, is that you seem to be passing strings ('01-may-2017' is a string) where you should have passed dates. I'd suggest you to use date literals, such as
SELECT *
FROM TABLE (fdr_dal_txns.get_txn_trans_adjst_consol (
short_string_col ('1BFV'),
'POST_DT',
short_string_col ('MCH', 'GP3', 'OTC'),
DATE '2017-05-01', --'01-may-2017',
DATE '2017-06-30' --'30-june-2017'
))
WHERE trd_id_num IN ('17FHKBBSSML', '17FHVBBRJD8')
and see what happens. If it still doesn't help, you should provide much more details of what you're doing (because you told us close to nothing so far).

Pervasive Control Center SQL INTO Error

I am getting an error in PCC which doesn't make a lot of sense. I have two statements inside a user defined function that are nearly exactly the same and one runs fine while the other is returning an error:
'INTO': Syntax error
end and start are parameters being passed to the function.
The Error is being thrown on the second INTO statement
SELECT count(*) INTO :divModelTot1
FROM "table1"."info" i
WHERE i.compldate <:end
AND (i.agree is null OR i.agree>:start)
UNION ALL
SELECT count(*) INTO :divModelTot2
FROM "table2"."info" i
WHERE i.compldate <:end
AND (i.agree is null or i.agree>:start);
Any help or suggestions would be appreciate.
Thanks!
SELECT INTO must be the first query in a statement containing a UNION.
SELECT count(*) INTO :divModelTot1
FROM "table1"."info" i
WHERE i.compldate <:end
AND (i.agree is null OR i.agree>:start)
UNION ALL
SELECT count(*)
FROM "table2"."info" i
WHERE i.compldate <:end
AND (i.agree is null or i.agree>:start);

Error using iif in ms access query

I am trying to fire this query in MS Access
SELECT file_number,
IIF(invoice_type='Spent on Coding',SUM(CINT(invoice_amount)), 0) as CodingExpense
FROM invoice
GROUP BY file_number
I am getting this error
Error in list of function arguments: '=' not recognized. Unable to
parse query text.
I tried replacing IIF with SWITCH to no avail.
What's wrong with my query and how to correct this?
AFAIK, you need that round the other way:
Sum(IIF(invoice_type="Spent on Coding",CINT(invoice_amount), 0)) as CodingExpense
However, I would suggest:
Round(Sum(IIF(invoice_type="Spent on Coding",invoice_amount, 0)),0) as CodingExpense