Can't make view from multiple table - sql

I'm trying to learn about view in SQL. In my case, i can't execute statement to create view. Here is the statement:
CREATE VIEW VTOTALMINUTESEMPLOYEE (EMPL_KODE, EMPL_NAME,DATE_IN, TIME_IN, TIME_OUT, HASIL)
SELECT
EMPLOYEE.EMPL_KODE,
EMPLOYEE.EMPL_NAME,
ATTANDENCE.DATE_IN,
ATTANDENCE.TIME_IN,
ATTANDENCE.TIME_OUT,((TIME_OUT-TIME_IN)/60) AS "RESULT"
FROM EMPLOYEE
JOIN ATTANDENCE
ON EMPLOYEE.EMPL_KODE=ATTANDENCE.EMPL_KODE
This is the errror code :
SQL Message : -104 Invalid token
Engine Code : 335544569 Engine Message : Dynamic SQL Error SQL
error code = -104 Token unknown - line 2, column 9 SELECT
What's wrong with my code ? is there a thing that i missed ? i run the code with flamerobin. please help.
Edit: I get following error:
-104 Invalid token Engine Code : 335544569 Engine Message : Dynamic SQL Error SQL error code = -104 Token unknown - line 2, column 9
SELECT

create view emp_attd_dtls
as
select
emp.emp_id,
t.empname,
attend_dateout,
attend_datein,
attend_timein,
attend_timeout
from employee emp
inner join emp_attend t on emp.emp_id =t.emp_id

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.

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.

Nested select statements in impala sql

I have the following SQL query in impala
SELECT currentdate,close
FROM ( SELECT * FROM spyprice)
Where currentdate between '2015-01-16' and '2016-06-17';
And it is giving me the error:
Starting Impala Shell without Kerberos authentication
ERROR: AnalysisException: Syntax error in line 15:
WHERE currentdate BETWEEN '2015-01-16' and '2016-06-17'
^
Encountered: WHERE
Expected: AS, DEFAULT, IDENTIFIER
CAUSED BY: Exception: Syntax error
Anyone knows what's going on?
Thanks in advance!
#James Xiang The right syntax of the query statement is :
SELECT a.currentdate, a.close FROM
(
SELECT * FROM spyprice
) a
Where a.currentdate between '2015-01-16' and '2016-06-17';

SQL error in DB2

I am trying to find the average number of transactions for every product key for the specified time keys. This is the query in DB2.
select
act.product_key
avg(act.cnt) as avg_transaction
from tb1 as ca
inner join tb2 as act
on ca.base_key = act.base_key and act.time = ca.time and act.product_key = ca.product_key
group by act.product_key, act.time
having act.time in (16476,16516, 16556,16596, 16636,16676,16716, 16756, 16796,16836,16876,16916,16956);
This is the error I am getting for the above query. I am not sure whats going wrong, this is the first time I am querying on DB2. Any suggestions would be great.
Error: DB2 SQL Error: SQLCODE=-104, SQLSTATE=42601, SQLERRMC=(;act.product_key
avg;,, DRIVER=3.66.46
SQLState: 42601
ErrorCode: -104
Error: DB2 SQL Error: SQLCODE=-727, SQLSTATE=56098, SQLERRMC=2;-104;42601;(|act.product_key
avg|,, DRIVER=3.66.46
SQLState: 56098
ErrorCode: -727
The way you describe what you want, you should move the having to a where clause and remove the time key from the group by:
select act.product_key, avg(act.cnt) as avg_transaction
from tb1 ca inner join
tb2 act
on ca.base_key = act.base_key and act.time = ca.time and act.product_key = ca.product_key
where act.time in (16476, 16516, 16556,16596, 16636, 16676, 16716, 16756, 16796, 16836, 16876, 16916, 16956)
group by act.product_key;
I'm not sure if that will fix your problem.

Advantage Database 8.1 SQL IN clause

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> )