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.
Related
I am running below query in Snowflake:
UPDATE PROVIDER_XO_SCORE_TABLE AS PXS
SET PXS.PROVIDER_ID = (SELECT P.PROVIDER_ID
FROM PROVIDER_TABLE P
WHERE PXS.XPI = P.XPI);
This query working fine in MySql but giving below error message in Snowflake.
SQL compilation error:
Unsupported subquery type cannot be evaluated
You can use the join-like syntax with UPDATE...FROM:
UPDATE PROVIDER_XO_SCORE_TABLE PXS
SET PROVIDER_ID = P.PROVIDER_ID
FROM PROVIDER_TABLE P
WHERE PXS.XPI = P.XPI;
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.
I have one main table and two support table. I need to extract information from all three tables into one table. However, the two support table have conflicting information. Thus, in the big table, only certain rows should have the value from one of the support table while others should have the value from the other support table. I would like to choose the data inputted base on some condition using a CASE statement
This sql code is within an R language code for other purposes. But the sql code is independent and no errors are related to the R code. The A.A11 and C.C1 are all type character while A.A12 and C.C1 are all numeric.
"SELECT ",
"A.A1, A.A3,",
"CASE",
"WHEN A.A12 = 0 THEN C.C6, C.C7",
"ELSE B.B6, B.B7",
"END",
"FROM ((A",
"INNER JOIN B",
"ON A.A12 = B.B1)",
"INNER JOIN C",
"ON CAST(A.A11 AS varchar(10)) = CAST(C.C1 AS varchar(10)))"
Warning in sqlExecute(con, query, sqlParams, fetch = TRUE, stringsAsFactors = FALSE) :
42000 102 [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near ','.
Warning in sqlExecute(con, query, sqlParams, fetch = TRUE, stringsAsFactors = FALSE) :
42000 8180 [Microsoft][ODBC SQL Server Driver][SQL Server]Statement(s) could not be prepared.
Warning: Error in sqlExecute: 42000 102 [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near ','.
42000 8180 [Microsoft][ODBC SQL Server Driver][SQL Server]Statement(s) could not be prepared.
[RODBCext] Error: SQLExecute failed
As near as I can tell, you want to do something along these lines...
SELECT
A.A1,
A.A3,
CASE WHEN A.A12 = 0 THEN C.C6 ELSE B.6 END AS X6,
CASE WHEN A.A12 = 0 THEN C.C7 ELSE B.7 END AS X7,
FROM A INNER JOIN B ON A.A12 = B.B1
INNER JOIN C ON CAST(A.A11 AS varchar(10)) = CAST(C.C1 AS varchar(10))
I am trying to migrate data from mysql to hive.I am not able to write a subquery case when statement with IN clause.This is my query. Can you Please help in this regard. AM i not following the proper syntax .
CREATE TABLE HIVE_TPCE_TEMP.TMP_CDMA_CD AS
SELECT A.DRI,C.BOUND_ID,A.CT_ID,A.CD_ID,A.CID,
A.TID,A.TASK_SEQ_ID,A.DIV_ID,C.BLOCK_GROUP_ID,C.ZIP_CODE,C.ROAD_CATEGORY_ID,A.RXPOWER,"${hiveconf:C_CDMA_DEVICE_ONLINE_RXPOWER_METRIC_ID}" METRIC_ID,
CASE WHEN
((A.DRI,A.DIV_ID,A.RFID) in (SELECT DRI,DIV_ID,HOME_RFID FROM HIVE_TPCE_TEMP.TMP_HOME_NETWORKS)) THEN
CASE WHEN MODE IN ('A','N') THEN "${hiveconf:HAD}" ELSE "${hiveconf:HD}" END
WHEN (COALESCE(A.RFID,0) = 0) AND ((A.DRI,A.DIV_ID,D.FR,D.SUBBAND) IN (SELECT DRI,DIV_ID,HOME_FR,
HOME_SUBBAND FROM HIVE_TPCE_TEMP.TMP_HOME_NETWORKS))
THEN CASE WHEN MODE IN ('A','N') THEN "${hiveconf:HAD}" ELSE "${hiveconf:HD}" END
ELSE CASE WHEN MODE IN ('A','N') THEN "${hiveconf:PAI}" ELSE "${hiveconf:PDI}" END END HPDA_ID
FROM HIVE_TPCE.VW_CDMA_CD A INNER JOIN HIVE_TPCE.STG_CURRENT_FILES B
ON A.DRI = B.DRI AND A.SOURCE_FILE_ID = B.SOURCE_FILE_ID
INNER JOIN
HIVE_TPCE.WRK_LOCATION C
ON A.DRI = C.DRI AND A.LOCATION_ID = C.LOCATION_ID
INNER JOIN
HIVE_TPCE.LU_RADIO D
ON A.RADIO_ID = D.RADIO_ID WHERE A.CID > 0 AND D.MODE IN ('A','N') AND A.RXPOWER IS NOT NULL AND A.CALL_RESULT_ID BETWEEN 1 AND 16;
My error signature is
FAILED: ParseException line 10:42 mismatched input ',' expecting ) near 'DRI' in expression specification
According to the Hive Language Manual: "Hive supports subqueries only in the FROM clause".
Your CASE WHEN is part of the SELECT clause, but it includes includes a SELECT subquery. Seems like that is not supported, so your syntax is not correct (in Hive).
Perhaps you could stage the data in MySQL using the query you have and then load it into Hive using a simple SELECT without CASE WHEN?
See official document.
It says
Assumptions
We plan to limit the scope with the following assumptions and limitations.
Subqueries could only be top-level expressions in SELECT. That is, subqueries in complex expressions, aggregates, UDFs, etc. will not be supported for now
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> )