Syntax Error: ON RIGHT when trying to match a substring in Impala - sql

Does anyone know why I am receiving this error? I am using SQL in IMPALA and it wont run. Theres a yellow underline under mem_register_hsty_view and transparency_services_summary_2018.
Here is my code:
use sndbx_dx;
SELECT
r.member_identifier,
n.fst_nme
FROM mem_register_hsty_view n
JOIN transparency_services_summary_2018 r
ON RIGHT(TRIM(r.member_identifier),4) = LEFT(n.fst_nme,4)
ORDER BY
r.id_key,
r.group_number,
n.fst_nme;
Here is the error:
AnalysisException: Syntax error in line 1:undefined: ...ervices_summary_2018 r ON RIGHT(TRIM(r.member_identifi... ^ Encountered: RIGHT Expected: CASE, CAST, DEFAULT, EXISTS, FALSE, IF, INTERVAL, NOT, NULL, REPLACE, TRUNCATE, TRUE, IDENTIFIER CAUSED BY: Exception: Syntax error

From the current Impala documentation the functions for taking some number of characters from the left or right of the string appear to actually be STRLEFT and STRRIGHT, respectively. Apply this to your current query gives:
SELECT
r.member_identifier,
n.fst_nme
FROM mem_register_hsty_view n
INNER JOIN transparency_services_summary_2018 r
ON STRRIGHT(TRIM(r.member_identifier), 4) = STRLEFT(n.fst_nme, 4)
ORDER BY
r.id_key,
r.group_number,
n.fst_nme;

Related

Problematic syntax error near ")" at line 14: SQL statement - SAP Hana

I am sure that you are used to this question but nonetheless I am having trouble with my SQL script. It is very frustrating.
When I execute the SQL against the SAP Hana database, I continuously receive this error:
Errors occurred while executing the SQL statement: SAP DBTech JDBC: [257]: sql syntax error: incorrect syntax near ")": line 14 col 35
Let me present the SQL concerned here:
SELECT
BKPF.BKTXT, BKPF.MONAT, BSEG.BELNR, BSEG.BUKRS, BSEG.DMBTR, BSEG.GJAHR, BSEG.MANDT, BSEG.PRCTR, BSEG.SAKNR, CEPCT.KTEXT, CEPCT.LTEXT, SKAT.MCOD1, SKAT.TXT20, SKAT.TXT50
FROM
SAPPR1.BSEG
INNER JOIN SAPPR1.BKPF ON BSEG.GJAHR = BKPF.GJAHR
INNER JOIN SAPPR1.CEPCT ON BSEG.PRCTR = CEPCT.PRCTR
INNER JOIN (SELECT
SAKNR, TXT20, TXT50, MCOD1
FROM
SAPPR1.SKAT
WHERE
SPRAS not LIKE '%[a-z0-9 .]%' ) AS SKAT_SUB ON BSEG.SAKNR = SKAT_SUB.SAKNR
WHERE
BKPF.MONAT = (SELECT Month('?')-1)
AND (BSEG.GJAHR = (SELECT Year('?')-1 HAVING Month('?')-1 < 4) OR BSEG.GJAHR = (SELECT Year('?') HAVING Month('?')-1 > 3))
AND BSEG.MANDT = ?
;
Unlike other DBMS HANA does not support selecting records out of nothing.
A SELECT without a FROM is not valid.
In order to create a single-row set one can use the DUMMY table.
SELECT current_date FROM DUMMY;
creates the single-row set with the result of the function expression.
Having said that, for comparisons a set is not required. Instead the function can be directly put into the expression:
WHERE
BKPF.MONAT = (MONTH(?)-1)
Also note that for string typed bind variables no quotation marks are required or allowed.

Using CASE as a join condition in Hive

I'm trying to run a query in Hive where I run a join based on a case statement. For some reason, I'm having problems on lines 7 and 8. I have not been able to resolve the error which is
line 7: Expected: AND, AS, BETWEEN, DIV, ILIKE, IN, IREGEXP, IS, LIKE, NOT, OR, REGEXP, RLIKE CAUSED BY: Exception: Syntax error
line 8: Encountered: AS Expected: AND, BETWEEN, DIV, ILIKE, IN, IREGEXP, IS, LIKE, NOT, OR, REGEXP, RLIKE CAUSED BY: Exception: Syntax error
select * from dra_record_set.mark_set inv
INNER JOIN innerdb.name_set roll_table
on inv.record_id = roll_table.ply_record_id AND
roll_table.date =
(CASE
WHEN inv.purchase_day>0 AND inv.purhcase_date BETWEEN roll_table.discount_start_dt AND roll_table.discount_end_dt) THEN inv.purchase_date
ELSE WHEN (CONCAT(inv.purchase_yr,inv.purchase_mo,(CAST("15")AS INT))) AS temp_var BETWEEN roll_table.discount_start_dt AND roll_table.discount_end_dt) THEN inv.purchase_date
END AS temp_pur_dt)
WHERE inv.inroll_discount_eligible_flag =1
limit 10
case is an expression. It returns a value. Your seems to be more like a macro substitution for SQL code.
Remove the case and just use boolean logic:
from dra_record_set.mark_set inv join
innerdb.name_set roll_table
on inv.record_id = roll_table.ply_record_id and
( (inv.purchase_day > 0 and
inv.purhcase_date between roll_table.discount_start_dt and roll_table.discount_end_dt
) or
(inv.purchase_day <= 0 and
CONCAT(inv.purchase_yr, inv.purchase_mo, 15) between roll_table.discount_start_dt AND roll_table.discount_end_dt
)
)

SQL UPDATE - INNER JOIN QUERY

I am trying to do an update in 2 tables, but i have this error:
Error SQL: ORA-00933: "SQL command not properly ended".
Could you help me please? The query is:
UPDATE a
SET a.ACTORID_ = SUBSTR(a.ACTORID_, 2, LENGTH(a.ACTORID_)),
b.TASKACTORID_ = SUBSTR(b.TASKACTORID_, 2, LENGTH(b.TASKACTORID_))
FROM jbpm_taskinstance AS a
INNER JOIN jbpm_log AS b
ON b.TASKACTORID_ = a.ACTORID_
WHERE a.ACTORID_ = b.TASKACTORID_
AND b.TASKINSTANCE_ IN (
SELECT ID_
FROM jbpm_taskinstance
WHERE a.PROCINST_ =b.PROCINST_)
AND b.TASKACTORID_ = a.ACTORID_;
Welcome to the world of strange and misleading Oracle error messages!
With experience, you can spot the error by sight, as #a_horse_with_no_name has done.
If you don't see the error immediately, I'd recommend to make the query simpler step by step until the error disappears. In your case, I would remove the AND b.taskinstance_ IN () subquery and check if the same error comes up. Then I'd remove the SUBSTR with a simple constant, like SET a.ACTORID_ = 'a'. Then I'd remove the JOIN, updating only table A. This will run ok, so you need to read up Oracle's documentation on UPDATE.

Cannot run the query as it says "unable to execute query, invalid operation or syntax using multi-valued field" in Access

SELECT
tbl_facilityinformation.exportid,
qry_numberofpatientsgreaterthan12withdepressionscreen.numberofuniquepatientsagegreaterthan12withdepressionscreening AS NumberUniquePatientsWithDepressionScreening,
qry_numberofuniquepersonsgreaterthan12years.numberofuniquepersonsgreaterthan12years,
[qry_numberofpatientsgreaterthan12withdepressionscreen]![numberofuniquepatientsagegreaterthan12withdepressionscreening] /
[qry_numberofuniquepersonsgreaterthan12years]![numberofuniquepersonsgreaterthan12years] AS PercentageOfPatientsGreaterThan12WithDepressionScreen
FROM
(
tbl_facilityinformation INNER JOIN qry_numberofpatientsgreaterthan12withdepressionscreen ON
tbl_facilityinformation.exportid = qry_numberofpatientsgreaterthan12withdepressionscreen.exportid
)
INNER JOIN qry_numberofuniquepersonsgreaterthan12years ON
tbl_facilityinformation.exportid = qry_numberofuniquepersonsgreaterthan12years.exportid
GROUP BY
tbl_facilityinformation.exportid,
qry_numberofpatientsgreaterthan12withdepressionscreen.numberofuniquepatientsagegreaterthan12withdepressionscreening,
qry_numberofuniquepersonsgreaterthan12years.numberofuniquepersonsgreaterthan12years;
I dont understand why I'm getting the error:
Unable to execute query, invalid operation or syntax using multi-valued field.
I have tried to look for syntax errors but could not find any.

Trying to complete an ISNULL but get the error [BC30198] ')' expected

I am getting the following error when trying to complete the query below.
The Value expression for the textrun
‘i_own_name.Paragraphs[0].TextRuns[0]’ contains an error: [BC30198]
')' expected.
Query is:
SELECT
,pi_appl_inspection.i_actual_date
,pi_appl_inspection.i_onsite_min
,pi_appl_inspection.a_location_unit
,pi_appl_inspection.i_own_name
,pi_appl_inspection.cplm_street_type
,pi_appl_inspection.a_inspect_desc
,ISNULL (pi_appl_inspection.a_inspect_desc, ISNULL(pi_appl_master.h_description1, pi_appl_inspection.i_own_name))AS EstablishmentName
FROM
pi_appl_inspection
LEFT OUTER JOIN pi_appl_master
ON pi_appl_inspection.a_reference_no = pi_appl_master.a_reference_no AND pi_appl_inspection.i_parcel_id = pi_appl_master.a_parcel_id
If your query is correctly displayed above, in addition to WingedPanther73's response (the comma before the first selected row is out of place), there needs to be a space between the last parenthesis and the "AS". I think that might trigger the error.