Cognos Analytics: QE-DEF-0459 on a CASE WHEN expression - sql

I am trying to create a new data item based on certain conditions. I did run across a couple of threads regarding this very issue, but I either don't know what syntax I need or I can't find where my syntax error is located. I am receiving a parsing error: QE-DEF-0459, QE-DEF-0260, and QE-DEF-0261
for the below code.
CASE
WHEN [Shipping].[Wave PARM].[MISC_STAT_CODE_2] =2 AND [ASRS_Lines] IS NOT NULL
THEN 'Sent'
WHEN [Shipping].[Wave PARM].[MISC_STAT_CODE_2] !=2 AND [ASRS_Lines] IS NOT NULL
THEN 'Not Sent'
ELSE NULL
END
I can't seem to figure out how to correct this error and any help would be greatly appreciated.
I have also tried...
IF [Shipping].[Wave PARM].[MISC_STAT_CODE_2] = 2 AND [ASRS_Lines] IS NOT NULL
THEN 'Sent'
ELSE IF [Shipping].[Wave PARM].[MISC_STAT_CODE_2] != 2 AND [ASRS_Lines] IS NOT NULL
THEN 'Not Sent'
ELSE NULL
END
Thank you in advance.

There is only one item that Cognos may take issue with there. Try <> instead of !=.
If that doesn't fix the problem, try deleting that data item and validating the report. If it still fails, that data item is not where the problem is.

Related

I am working in datastage and I am trying to input data from one column to another

I used the following statement below:
Trim(IF FromDataSource.PID_VALID = 'Y' THEN FromDataSource.Person_ID ELSE #NULL)
Assuming you are using this code within a Transformer stage in DataStage
this will help
IF Trim(FromDataSource.PID_VALID) = 'Y' THEN Trim(FromDataSource.Person_ID) ELSE #NULL
Hint:
For you next question you might ask in this forum you should provide more details - do not let us guess. Also describe what you have tried and what error you got etc.
You can use case expression :
(CASE WHEN FromDataSource.PID_VALID = 'Y' THEN TRIM(FromDataSource.Person_ID) END)
else will return null if condition evaluate as false, you don't need to specify null.
If you want to set null if PID is not valid then->
IF FromDataSource.PID_VALID = 'Y' THEN trim(FromDataSource.Person_ID) ELSE setnull()
If you want to set empty when PID is not valid then->
IF FromDataSource.PID_VALID = 'Y' THEN trim(FromDataSource.Person_ID) ELSE ''

Dreaded "Missing Right Parenthesis" Error in Oracle SQL

We access an Oracle database through a web application. The web application is published, hosted and administered off-site. One component of the web application are dashboards, which use SQL to return data from the system on regular intervals that are then displayed and can trigger alarms should certain thresholds be reached.
The SQL has several parameters that are assigned in the dashboard setup: LOCATION, OWNER_DEPT, USING_DEPT and DAYS_AHEAD and appear to be working properly. Here is the query:
SELECT * FROM
(
SELECT DISTINCT
"MFIVE"."VIEW_WORK_REQ_OCC"."UNIT_NO" AS "UNIT NO", "MFIVE"."VIEW_WORK_REQ_OCC"."WORK_REQ_NO" AS "WORK REQ NO", "MFIVE"."VIEW_WORK_REQ_OCC"."JOB" AS "JOB",
CASE WHEN "MFIVE"."VIEW_WORK_REQ_OCC"."DUE_DATE" IS NULL THEN NULL ELSE ("MFIVE"."VIEW_WORK_REQ_OCC"."DUE_DATE") END AS "DUE DATE",
CASE WHEN "MFIVE"."VIEW_WORK_REQ_OCC"."FIRST_DATE" IS NULL THEN NULL ELSE ("MFIVE"."VIEW_WORK_REQ_OCC"."FIRST_DATE") END AS "FIRST DATE",
CASE WHEN "MFIVE"."VIEW_WORK_REQ_OCC"."LAST_DATE" IS NULL THEN NULL ELSE ("MFIVE"."VIEW_WORK_REQ_OCC"."LAST_DATE") END AS "LAST DATE"
FROM "MFIVE"."VIEW_WORK_REQ_OCC"
WHERE
("MFIVE"."VIEW_WORK_REQ_OCC"."MNT_PREVENTIVE_FL" = 'Y') AND
(UPPER("MFIVE"."VIEW_WORK_REQ_OCC"."LOCATION") LIKE UPPER(CONCAT(CONCAT('%', ':<LOCATION>'), '%'))) AND
(UPPER("MFIVE"."VIEW_WORK_REQ_OCC"."OWNER_DEPT") LIKE UPPER(CONCAT(CONCAT('%', ':<OWNER_DEPT>'), '%'))) AND
(UPPER("MFIVE"."VIEW_WORK_REQ_OCC"."USING_DEPT") LIKE UPPER(CONCAT(CONCAT('%', ':<USING_DEPT>'), '%'))) AND
("MFIVE"."VIEW_WORK_REQ_OCC"."DUE_DATE" >= SYSDATE + ':<DAYS_AHEAD>')
ORDER BY
"MFIVE"."VIEW_WORK_REQ_OCC"."UNIT_NO" ASC,
"MFIVE"."VIEW_WORK_REQ_OCC"."JOB" ASC,
CASE WHEN "MFIVE"."VIEW_WORK_REQ_OCC"."DUE_DATE" IS NULL THEN NULL ELSE ("MFIVE"."VIEW_WORK_REQ_OCC"."DUE_DATE") END AS "DUE DATE" ASC
)
The issue is with the statements involving "MFIVE"."VIEW_WORK_REQ_OCC"."DUE_DATE". We're attempting to return only values where DUE_DATE is greater than the SYSDATE plus the value in the DAYS_AHEAD parameter. Deleting these lines allows the query to execute properly; leaving them as-is returns the error ORA-00907: missing right parenthesis.
The majority of the SQL was lifted from the SQL as generated by an ad-hoc reporting component of the web application. The report runs properly, but we are not able to pass parameters through the ad-hoc reporting module. The modifications to the original were to add the bind variables.
I'm hoping someone can point me in the correct direction to remedy this issue. Any assistance is appreciated.
Thanks to Kaushik Nayak for helping me see the forest for the trees.
The correction only affects the ORDER BY clause:
...
ORDER BY
"MFIVE"."VIEW_WORK_REQ_OCC"."UNIT_NO" ASC,
"MFIVE"."VIEW_WORK_REQ_OCC"."JOB" ASC,
)

Getting this error - ORA-00936: missing expression

I am new to SQL and trying to use an if statement equivalent in order to get the value in SQL.
After running this report I am getting the error "ORA-00936: missing expression"
CASE WHEN (select Sum(MONTANT) from fraisExterne where matching=fm.id and statut=3) IS NULL
THEN select sum(MONTANT) from fraisExterne where matching=fm.id
ELSE Select sum (MONTANTHTBROKER) from fraismatching where matching=fm.id
End End as "BROKER AMOUNT"
Please let us know if you can help me with it
You have a extra END key word at the end of your case statement. You also need to put your select query into ().
Try this:
SELECT
CASE
WHEN (select Sum(MONTANT) from fraisExterne where matching=fm.id and statut=3) IS NULL THEN (select sum(MONTANT) from fraisExterne where matching=fm.id)
ELSE (Select sum (MONTANTHTBROKER) from fraismatching where matching=fm.id)
End AS BROKER_AMOUNT
I hope this helps and welcome to StackOverflow. If you find this answer or any other answer solves your problem please mark it as the solution. This will help the community and fellow programmers who run into the same problem in the future. Thanks.

Crystal reports - How to translate a group by with condition into a report

I have the following query
SELECT dbo_DIRIGEANTS.IU_DIR,
[1-CR-liste_Pixi].Siren,
[1-CR-liste_Pixi].Nic,
FROM [1-CR-liste_Pixi] LEFT JOIN dbo_DIRIGEANTS ON [1-CR-liste_Pixi].Siren = dbo_DIRIGEANTS.SIREN
GROUP BY
dbo_DIRIGEANTS.IU_DIR,
[1-CR-liste_Pixi].Siren,
[1-CR-liste_Pixi].Nic,
IIf([QUAL_JUR]>"0003","",Right([QUAL_JUR],1))
HAVING
((([1-CR-liste_Pixi].Siren) Not Like "p*")
AND (([1-CR-liste_Pixi].Nic) Not Like "p*")
AND ((dbo_DIRIGEANTS.REP_LEGAL)="1") AND (([1-CR-liste_Pixi].Nicsiège) Not Like "p*"))
ORDER BY IIf([QUAL_JUR]>"0003","",Right([QUAL_JUR],1));
What I'm interested is setting that part
GROUP BY dbo_DIRIGEANTS.IU_DIR,
[1-CR-liste_Pixi].Siren,
[1-CR-liste_Pixi].Nic,
IIf([QUAL_JUR]>"0003","",Right([QUAL_JUR],1))
And especially that part
IIf([QUAL_JUR]>"0003","",Right([QUAL_JUR],1))
Because of performance, I kept my tables and use CR's functions to deal with the condition part instead of creating a query.
I did the following:
Went to Formula selection and choose group
Chose the field I wanted
Put the formula
The error below popped out
It said my formula needs to be using boolean values.
To see if I was right, I've amended it that way IF {DIRIGEANTS.QUAL_JUR} > "0003" THEN TRUE ELSE FALSE. It worked.
TL;DR
Why I cannot do that in my expert group selection?
IF {DIRIGEANTS.QUAL_JUR} > "0003" THEN "" ELSE RIGHT({QUAL_JUR},1)
Thanks
Group selection should return Boolean but that doesn't mean you write true or false....it means you pass some thing to fields to perform job
IF {DIRIGEANTS.QUAL_JUR} > "0003"
THEN datasefield=""
ELSE database fled=RIGHT({QUAL_JUR},1)
This will do the job
Edit: Apologize as conditions are a bit confused for your requirement
Create formula and write below code
IF {DIRIGEANTS.QUAL_JUR} > "0003" THEN ""
ELSE RIGHT({DIRIGEANTS.QUAL_JUR},1)
Now go to insert group and select this formula and click ok. This will do the trick

SQL Developer: invalid identifier error

This is the part of my query that has error:
, case when dsi.distributor_id in
('ALBQA','ASGLA','ASGNY','ASGR1','ASGSF','BIKU9','COAUU','CSWHP','DPIB1','DPID9',
'DPISP','DPISQ','EAS3X','GEP79','GRG8V','NACY7','NOSYK','ORGK7','PETR1','TOP0U',
'UNFIA','UNFIL','UNFIQ','UNFIS','UNMQ9','KOSI8','KEHEN','CSNYC','ALBQA','ALC6Y','BAM7D','BIKU9','CLCE0','COAUU','CSWHT','EAS3X','FOUXU','GEP79',
'GRG8V','HED9Q','LAOJD','MCLFS','NOSYK','ORGK7','UNMQ9','OMAH1'
)
then 'Distributor'
else 'Direct'
end as is_direct
, SUM(dsi.cost) AS tot_cost
, SUM(CASE WHEN is_direct = 'Direct' THEN dsi.cost ELSE 0 END ) AS Direct_cost
It says that is_direct is an invalid column but I already indicated it above. Therefore, I was wondering if you could help me find where I went wrong.
Columns defined in your query cannot be used in other places in your query, whether it is in other columns, or WHERE clauses, etc.
I would suggest either placing these calculations into subqueries, or using WITH AS.