CASE statement syntax error in SAP Lumira / Freehand SQL - sql

I’m using SAP Lumira desktop and "Query with SQL (Freehand SQL)", connected to SAP ECC. I try to extend the query with a case statement but run into errors as below:
SELECT "VBUK-UVALS",
CASE ("VBUK-UVALS") WHEN 'A' THEN 'Closed'
WHEN 'B' THEN 'Open'
ELSE 'Other'
END AS "ColumnA"
FROM "Local"."INFOSET"."ZCA_TESTAR"
Syntax error in SQL query:
[line 2:31 missing FROM at 'WHEN'][line 2:36 missing EOF at "A"]
It would be very appreciated if any could guide me through this

As the error suggests, your syntax is wrong. A case expression has only one case keyword, and can have multiple when clauses of the different values you're evaluating (and an optional single else clause):
SELECT "VBUK-UVALS",
CASE ("VBUK-UVALS") WHEN 'A' THEN 'Closed'
WHEN 'B' THEN 'Open' -- CASE ("VBUK-UVALS") removed
ELSE 'Other'
END AS "ColumnA"
FROM "Local"."INFOSET"."ZCA_TESTAR"

Sorry, to many “CASE”, It was a mistake by me when wrote the case.
The Query is stated as followed with the same error message
SELECT "VBUK-UVALS",
CASE ("VBUK-UVALS") WHEN 'A' THEN 'Closed'
WHEN 'B' THEN 'Open'
ELSE 'Other'
END AS "ColumnA"
FROM "Local"."INFOSET"."ZCA_TESTAR"
Syntax error in SQL query:
[line 2:27 missing FROM at 'WHEN'][line 2:32 missing EOF at "A"]

Related

Create multiple case statements in SAP HANA

I'm trying to understand how work the expression in SAP HANA.
I want to create multiple case in one expression.
I have this:
case when (case when "name" = 'NomEntreprise'
then "value"
end) = 'Entreprise Test'
Then 'OK'
end
But when I'm doing this, it doesn't accept the syntax of the code, someone can explain me why ?
case when (case when "name" = 'NomEntreprise'
then "value"
end) = 'Entreprise FAIL'
Then 'FAIL'
end
Thank you for you help

SQL query using if else

My SQL code looks like this:
SELECT
Scores.PupilId, Scores.BoysName, Scores.FormGroup,
IF (Scores.FormGroup = "10SB", "Great", "ok")
FROM
Scores
I get this message
no such function: if: SELECT Scores.PupilId, Scores.BoysName, Scores.FormGroup,
if(Scores.FormGroup="10SB","Great","ok")
FROM Scores
This is flat file database
Can anyone please help me understand why I am getting a message?
The correct ANSI-standard conditional expression in SQL is the case expression:
SELECT Scores.PupilId, Scores.BoysName, Scores.FormGroup,
(CASE WHEN Scores.FormGroup = '10SB' THEN 'Great' ELSE 'ok' END)
FROM Scores ;

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.

Is it possible to use CASE with ANY() in Oracle SQL?

Is possible to achieve what I'm trying to do in the below SQL query?
I want to check if the item name matches any of the given list.
select
case item_name
when any ('PEN', 'PENCIL', 'PAPER', 'ERASER') then 'STATIONARY'
else 'OTHER'
end is_stationary
from items;
I tried this query, and seems it is not possible. The error message is,
ORA-00936: missing expression
00936. 00000 - "missing expression"
*Cause:
*Action:
Error at Line: 29 Column: 10
Is there any other workaround to achieve this?
Try this
select
case when item_name IN ('PEN', 'PENCIL', 'PAPER', 'ERASER') then 'STATIONARY'
else 'OTHER'
end is_stationary
from items;
CASE .. IN .. REFERENCE LINK
#bvr's answer is by far the most common way to solve this problem. But it looks like you were very close to correctly using an alternative syntax, the
group comparison condition.
select
case
when item_name = any ('PEN', 'PENCIL', 'PAPER', 'ERASER') then 'STATIONARY'
else 'OTHER'
end is_stationary
from items;

Getting error ORA-00936: missing expression

When I trying the below SQL I am getting the error ORA-00936: missing expression. Please help me on this, I want distinct on those to columns in Oracle SQL
SELECT rr.RPT_QUE_I,
DISTINCT (rr.ed_sbmt_m, rr.RPT_RUN_STAT_C),
rr.rpt_cstm_x,
rr.rpt_cmplt_m,
CASE
WHEN rr.rpt_run_stat_c = 25453 THEN 'PENDING'
WHEN rr.rpt_run_stat_c = 25454 THEN 'ACTIVE'
WHEN rr.rpt_run_stat_c = 25455 THEN 'FINISHED'
WHEN rr.rpt_run_stat_c = 25458 THEN 'ERROR'
WHEN rr.rpt_run_stat_c = 25460 THEN 'SCHEDULED'
END,
cc.pro_sym_I,
rr.usr_wad_ownr_i
FROM audit_REPORT_RUN rr,
CLIENT_COMPANY cc
WHERE rr.ED_SBMT_M > TO_DATE('06/01/2012','mm/dd/yyyy')
AND rr.ED_SBMT_M < TO_DATE('07/01/2012','mm/dd/yyyy')
AND rr.ORG_I = cc.ORG_I
ORDER BY rr.RPT_QUE_I
You should use DISTINCT keyword at first after the SELECT keyword, and remove the parenthesis,
or if you need to categorize some of it, use GROUP BY functions. hope you're getting the desired result.