Invalid procedure call error in MS Access Sum - sql

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.

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}}

DB2 SQL How to get the last executed SQL-Statement with GET DIAGNOSTICS?

I want to call a procedure in RPG on IBM i with SQLSTATE and with a variable text.
getSQLMessage(SQLSTT: text)
The variable text should be the last executed sql statement before the procedure call.
Is there a opportunity to get it like this:
EXEC SQL GET DIAGNOSTICS CONDITION 1 :text = last executed sql statement
Or maybe someone knwos another solution for my problem?
Thanks a lot!
You can't use GET DIAGNOSTICS, but you can first get the JobLog
DSPJOBLOG OUTPUT(*OUTFILE) OUTFILE(QTEMP/ERR_LOG)
then get the last SQL Error:
Select Qmhmf,
Qmhmid,
Qmhmdt
From Qtemp.Err_Log
Where Qmhsev >= 20
And Substr(Qmhmid, 1, 3) In ('CPA' , 'CPD' , 'CPF' , 'SQL')
Order By Rrn(Err_log) Desc
Fetch First 1 Rows Only

SQL Hive subquery error

I have the query below
set hive.cli.print.header=true;
set hive.query.max.partition=1000;
set hive.mapred.mode=unstrict;
SELECT
dim_lookup("accounts",name,"account_id") = '28016' as company,
dim_lookup("campaigns",name,"campaign_id") in (117649,112311,112319,112313,107799,110743,112559,112557,105191,105231,107377,108675,106587,107325,110671,107329,107181,106565,105123,106569,106579,110835,105127,105243,107185,105211,105215) as campaign_name,
case when is_click_through=0 then "PV" else "PC" end as conv_type,
(SELECT COUNT(1) FROM impressions WHERE ad_info[2] in (117649,112311,112319,112313,107799,110743,112559,112557,105191,105231,107377,108675,106587,107325,110671,107329,107181,106565,105123,106569,106579,110835,105127,105243,107185,105211,105215)) AS impressions
FROM actions
WHERE
data_date>='20170101'
AND data_date<='20171231'
AND conversion_action_id in (20769223,20769214,20769219,20764929,20764932,20764935,20769215,20769216,20764919,20769218,20769217,20769220,20769222)
GROUP BY conv_type
When I execute it I get an error
ERROR ql.Driver: FAILED: ParseException line 8:1 cannot recognize input near 'SELECT' 'COUNT' '(' in expression specification
I am trying to fetch each count of impression for a specified conversion_action_id. What could be the error in my query? Thanks for the help.
FYI: ad_info[2] and campaign_id are the same.
The problem is quite clear, you have a subquery inside your SELECT.
That is not how this works.
Unfortunately the exact solution is not that clear, as it I am not completely sure what you want, but here is some general advice:
Write your subquery, test it and make sure it is ok
Rather than putting it in your SELECT part, put it in your FROM part, and (as always) SELECt from the FROM
Just think of your subquery output as an other table that can be used in the from statement, and which needs to be combined (JOIN, UNION?) with other tables in the from statement.

Advantage Database 8.1 SQL IN clause

Using Advantage Database Server 8.1 I am having trouble executing a successful query. I am trying to do the following
SELECT * FROM Persons
WHERE LastName IN ('Hansen','Pettersen')
To check for multiple values in a column. But I get an error when I try to execute this query in Advantage.
Edit - Error
poQuery: Error 7200: AQE Error: State = 42000; NativeError = 2115; [iAnywhere Solutions][Advantage SQL Engine]Expected lexical element not found: ( There was a problem parsing the
WHERE clause in your SELECT statement. -- Location of error in the SQL statement is: 46
And here is the SQL i'm executing
select * from "Pat Visit" where
DIAG1 IN = ('43644', '43645', '43770', '43771', '43772', '43773', '43774',
'43842', '43843', '43845', '43846', '43847', '43848', '97804', '98961',
'98962', '99078')
Done
Does anyone have any Idea how I could do something similar in advantage that would be efficient as well?
Thanks
You have an extraneous = in the statement after the IN. It should be:
select * from "Pat Visit" where
DIAG1 IN ('43644', '43645', <snip> )

SQL Error in VBA

I have the following code in SQL (2005) which calculates the avarage user logins on a systm:
with
user_total as
(
select COUNT(distinct ID) as counter
FROM [dbo].[LOG]
where [LOG].DESCRIPTION='Login success.'
AND
Convert(datetime,convert(char(10),[LOG].CREATED_ON,101)) BETWEEN '2009-01- 01' AND '2009-12-31'
),
USER_avg as
(
select counter/365 as Avarage_Daily_Logins
from user_total
)
select *
from USER_avg
Now the problem is when i put this in a VBA macro in excel to get the result in a spcific cell in strSQL = "QUERY SHOWN ABOVE HERE" argument i get the error in excel
incorrect sysntax near the keyword with
Its worth mentioning that i dont break the code in VBA in multiple lines..i have it all in one line.
Use ;WITH ...
WITH usage for a CTE must have ; after the previous statement. To ensure this is the cases, prefix with ;
Check all of your spacings, if there is an error further down the compiler may interpret it as a problem with the with statement.