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
Related
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}}
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.
SELECT
e.DESCRIPTION AS [EQUIPMENT TYPE],
Count(e.EQNAME) AS QUANTITY,
Sum(IIf(e.CONDITION = 'Functional', 1, 0)) AS WORKING,
Sum(IIf(e.CONDITION = 'Non-Functional', 1, 0)) AS [NON-WORKING]
FROM EQUIPMENTS AS e
GROUP BY e.DESCRIPTION;
I tried using this query in VB.net TableAdapter Query Configuration wizard and an error occurs.
Error in list of function arguments: '=' not recognized.
Unable to parse query text
Error in GROUP BY clause.
This Query works well in MS Access, what's the difference from it in VB.Net?
I already have a solution to this problem. I just used this query as a stored query in MS-Access then used in my VB.Net Code. Thank you guys.
My query is as follows :
I have written in access can anyone pls help how can I convert it into sql query I am getting an error near IIF condition.
SELECT #NT_VAR_STEP_1_1.SYS_ID, #NT_VAR_STEP_1_1.NODE, #NT_VAR_STEP_1_1.TEMP_ID,
#NT_VAR_STEP_1_1.EQUIP_TYPE, #NT_VAR_STEP_1_1.EQ_ID,
#NT_VAR_STEP_1_1.VAR_ID, #NT_VAR_STEP_1_1.NODE AS VAR_SET,
#NT_VAR_STEP_1_1.VAR_NAME, IIf([#NT_VAR_STEP_1_1]![VAR_SUBSET]=‘SELF’,
[#NT_VAR_STEP_1_1]![NODE],[#NT_VAR_STEP_1_1]![VAR_SUBSET]) AS VAR_SUBSET,
IIf([#NT_VAR_STEP_1_1]![EQUIP_TYPE]=‘SOURCE’,’PARAMVAR’,’VAR’) AS CALC_VAR_TYPE,
#NT_VAR_STEP_1_1.VAR_DATA_TYPE AS DATA_TYPE, #NT_VAR_STEP_1_1.DOF,
#NT_VAR_STEP_1_1.RETAIN, #NT_VAR_STEP_1_1.COEFF_OBJECT,
#NT_VAR_STEP_1_1.COEFF_VAR_SET, #NT_VAR_STEP_1_1.COEFF_VAR_TYPE,
#NT_VAR_STEP_1_1.COEFF_VAR_SUBSET, #NT_VAR_STEP_1_1.COEFF_VAR_NAME,
#NT_VAR_STEP_1_1.OPERAND, #NT_VAR_STEP_1_1.SIGN,
#NT_VAR_STEP_1_1.VAR_TP_OFFSET, #NT_VAR_STEP_1_1.COEFF_TP_OFFSET,
#NT_VAR_STEP_1_1.COEFF_VAR_SUBTYE INTO #OT_VAR_STEP_1_1_1
FROM #NT_VAR_STEP_1_1
GROUP BY #NT_VAR_STEP_1_1.SYS_ID, #NT_VAR_STEP_1_1.TEMP_ID,
#NT_VAR_STEP_1_1.EQUIP_TYPE, #NT_VAR_STEP_1_1.EQ_ID,
#NT_VAR_STEP_1_1.VAR_ID, #NT_VAR_STEP_1_1.NODE,
#NT_VAR_STEP_1_1.VAR_NAME, IIf([#NT_VAR_STEP_1_1]![VAR_SUBSET]=‘SELF’,
[#NT_VAR_STEP_1_1]![NODE],[#NT_VAR_STEP_1_1]![VAR_SUBSET]),
IIf([#NT_VAR_STEP_1_1]![EQUIP_TYPE]=‘SOURCE’,’PARAMVAR’,’VAR’),
#NT_VAR_STEP_1_1.VAR_DATA_TYPE, #NT_VAR_STEP_1_1.DOF,
#NT_VAR_STEP_1_1.RETAIN, #NT_VAR_STEP_1_1.COEFF_OBJECT,
#NT_VAR_STEP_1_1.COEFF_VAR_SET, #NT_VAR_STEP_1_1.COEFF_VAR_TYPE,
#NT_VAR_STEP_1_1.COEFF_VAR_SUBSET, #NT_VAR_STEP_1_1.COEFF_VAR_NAME,
#NT_VAR_STEP_1_1.OPERAND, #NT_VAR_STEP_1_1.SIGN,
#NT_VAR_STEP_1_1.VAR_TP_OFFSET, #NT_VAR_STEP_1_1.COEFF_TP_OFFSET,
#NT_VAR_STEP_1_1.COEFF_VAR_SUBTYE, #NT_VAR_STEP_1_1.NODE
HAVING (((#NT_VAR_STEP_1_1.EQUIP_TYPE)<>‘COST_NODE’));
Convert this line:
IIf([#NT_VAR_STEP_1_1]![EQUIP_TYPE]=‘SOURCE’,’PARAMVAR’,’VAR’) AS CALC_VAR_TYPE
to this:
CASE WHEN [#NT_VAR_STEP_1_1].[EQUIP_TYPE]='SOURCE'
THEN 'PARAMVAR'
ELSE 'VAR'
END CALC_VAR_TYPE
And then use the same in your GROUP BY clause, but without the column alias:
CASE WHEN [#NT_VAR_STEP_1_1].[EQUIP_TYPE]='SOURCE'
THEN 'PARAMVAR'
ELSE 'VAR'
END
I will assume you're going to SQL Server (T-SQL). T-SQL does not support IIF, you will need to use CASE instead.
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