Invalid SQL Syntax CLI0118E - sql

I am trying to execute the below query and getting Invalid SQL Syntax error
. [IBM][CLI Driver] CLI0118E Invalid SQL syntax. SQLSTATE=37000(37000,-99999). Is it anything to do with driver upgrade? It was working fine a while ago. Please advice. Thanks in advance.
select a.name_task as nameTask, a.cd_sts as cdSts, a.desc_err_msg as
statusDesc
from task_log a,(
select id_bus_procss, name_task , id_run,
max(dt_lst_updt) as dt_lst_updt from task_log
where id_run = '1'
and id_bus_procss = '14'
and name_task in ({0})
and dt_lst_updt >= (
select dt_evnt_sts from
sf_evntflow_sts
where id_run = '1' and
id_evntflow ='15'
and cd_evnt_sts in (''CLN'',''RTY'' )
)
group by id_bus_procss, name_task, id_run)
X
where a.dt_lst_updt = X.dt_lst_updt

if you are executing this on stored procedure , Try this may help, Remove the new line character and separate the parameters by
spaces .
Or otherwise try upgrade.......

if you try this query its better?
select a.name_task as nameTask, a.cd_sts as cdSts, a.desc_err_msg as statusDesc
from task_log a,
( select b.id_bus_procss, b.name_task , b.id_run, max(b.dt_lst_updt) as dt_lst_updt
from task_log b inner join sf_evntflow_sts c on b.id_run=c.id_run and c.id_evntflow ='15'
and c.cd_evnt_sts in (''CLN'',''RTY'' ) and b.dt_lst_updt >=c.dt_evnt_sts
where b.id_run = '1' and b.id_bus_procss = '14' and b.name_task in ({0})
group by b.id_bus_procss, b.name_task, b.id_run
) as X
where a.dt_lst_updt = X.dt_lst_updt

Related

sql server error msg 116, how to bypass

I have a problem with a subquery in my query.
In this query :
SELECT *
FROM Statistic_RecordedConversations A
JOIN (SELECT DID, max(DateTime) MaDate
FROM Statistic_RecordedConversations
where DID IN (
Select OpenData as DID, QuestionID, InterviewID
from Surveys.dbo.Askia2363Data
where QuestionID = 895
and InterviewID in (
select Surveys.dbo.Askia2363Data.InterviewID
from Surveys.dbo.Askia2363Interview,
Surveys.dbo.Askia2363Data
where Surveys.dbo.askia2363Interview.InterviewID =
Surveys.dbo.Askia2363Data.InterviewID
and completed = 1
and QuestionID = 891
and ClosedData = 4685
and CAST(EndInterview as Date) =
CAST (Current_TIMESTAMP as Date)))
GROUP BY DID ) B
ON A.DID = B.DID
AND A.DateTime = B.MaDate
I got an error with msg 116. I think its due to the ligne 6 where I have not only 1 column. I don't know how to get this query working. I tried EXISTS insteand of IN but got too many results and not the results that are interesting to me.
If someone got another solution, many thanks! :)
You can only return one field to correlate inside of an IN statement. You need to only return DID.
where DID IN ( Select OpenData as DID from Surveys.dbo.Askia2363Data...

sql syntax error whith where and group by

I wrote a command in sql server 2014 , the command fails with the following error
command
select * from View_FirstReport
where Date Between '1392/03/20' and '1392/03/19', Insure_ID = '0', User_ID='2'
Group by insure_id, InsureTitle, status
error
Msg 102, Level 15, State 1, Line 2 Incorrect syntax near ','.
You should combine the parts of your query with AND and OR.
select
*
from
View_FirstReport
where
Date Between '1392/03/20' and '1392/03/19'
AND Insure_ID = '0'
AND User_ID='2'
Group by insure_id, InsureTitle, status
Replace the , in your WHERE clause with AND:
SELECT *
FROM View_FirstReport
WHERE
Date Between '1392/03/20' AND '1392/03/19'
AND Insure_ID = '0' AND User_ID='2'
GROUB BY insure_id,InsureTitle,status
A detailed syntax definition of WHERE can for example be found here.
Use AND instead of ,:
SELECT * FROM View_FirstReport
WHERE Date BETWEEN '1392/03/20' and '1392/03/19'
AND Insure_ID = 0
AND User_ID = 2
GROUP BY insure_id, InsureTitle, status
Also, integer columns do not require single quote to surround the values.
You should have to replace your , with and operator and select only those records which you are including in group or MIN , MAX , AVG etc for other columns.
SELECT insure_id, InsureTitle, status FROM View_FirstReport
WHERE Date BETWEEN '1392/03/20' and '1392/03/19'
AND Insure_ID = 0
AND User_ID = 2
GROUP BY insure_id, InsureTitle, status
Try like this,
SELECT insure_id
,InsureTitle
,[STATUS]
FROM View_FirstReport
WHERE [DATE] BETWEEN '13920320'
AND '13920319'
AND Insure_ID = '0'
AND [User_ID] = '2'
GROUP BY insure_id
,InsureTitle
,[STATUS]
This is almost similar to SandeepKumar answer.

SQL syntax or database constrictions?

I have 2 tables that have each a column MNR. I want to join them with this column.
The following two SQL statements fail. The last one shows that my date format is working (with changed session format). DB is Oracle.
Can someone please tell me what I'm doing wrong ? And what do I call this join ?
// fails
select a.CREATEDATE, a.BELEGNRRECH, a.MNR, a.UTNR, a.KTXT, b.ANR
from INFOR.RELFBR as a, INFOR.RELXDB as b
where (a.SAINT = '90') and (a.MNR = b.MNR) and (b.SAINT = '10')
and (a.CREATEDATE >= '01.01.2014 00:00:00')
order by a.CREATEDATE
// fails as well
select a.CREATEDATE, a.BELEGNRRECH, a.MNR, a.UTNR, a.KTXT, b.ANR
from INFOR.RELFBR as a, INFOR.RELXDB as b
where (a.SAINT = '90') and (a.MNR = b.MNR) and (b.SAINT = '10')
order by a.CREATEDATE
// all fine
select CREATEDATE, MNR
from INFOR.RELFBR
where (CREATEDATE >= '01.01.2014 00:00:00')
order by CREATEDATE
Failing error is ORA-00933: SQL command not properly ended
After removing "order by ..." same error occurs.
Exclude AS from table aliasing - AS can be used with selection list but not in FROM clause
select a.CREATEDATE, a.BELEGNRRECH, a.MNR, a.UTNR, a.KTXT, b.ANR
from INFOR.RELFBR a, INFOR.RELXDB b
where (a.SAINT = '90') and (a.MNR = b.MNR) and (b.SAINT = '10')
and (a.CREATEDATE >= '01.01.2014 00:00:00')
order by a.CREATEDATE
Example:
SQL> select * from t_dummy t;
X
-----------------------
9.0000
SQL> select * from t_dummy as t;
select * from t_dummy as t
*
error in line 1:
ORA-00933: SQL command not properly ended
Documentation:
http://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_10002.htm#i2126863

Update using CTE - Syntax error?

I'm trying to update a table using data contained in a CTE. Unfortunately I'm receiving a syntax error and I'm not quite sure why. The code currently is:
declare #period_id integer =
(
select period_id
from property.period
where getdate() between period_start and period_end
)
;with cte_reclassified as
(
select building_id ,
lease_id ,
scca_broad_category_code ,
scca_fine_categories_code ,
scca_notes_code ,
scca_sales_group_code ,
scca_uplift
from property.lease_period
where period_id = #period_id
)
update property.lease_period lp
from cte_reclassified r
set lp.scca_broad_category_code = r.scca_broad_category_code
where lp.lease_id = r.lease_id
and lp.building_id = r.building_id
The syntax error I'm receiving is:
Msg 102, Level 15, State 1, Line 21 Incorrect syntax near 'lp'.
Is there a way to do what i'm trying to attempt here? I've tried googling the subject but hit dead ends - any advice would be appreciated!
I think you want to take the "property" out of the UPDATE part of the statement (since you are updating through the CTE) and put the SET clause before the FROM:
update lease_period lp
set lp.scca_broad_category_code = r.scca_broad_category_code
from cte_reclassified r
where lp.lease_id = r.lease_id
You do not need to create alias on your update statement
On its syntax : Update [TableName] SET [ColumnName]='New Value' WHERE ColumnName='Filter'
have a look on this SO post on how it is done by #Robin Day:
SQL Server UPDATE from SELECT
Best Regards

HQL syntax problem

I have a problem with the following HQL query:
select sum(MYTABLE.COUNTER) from (
select count(DISTINCT bi.products.id) as COUNTER
from BusinessInformation as bi
where bi.informationOwners.id in (100)
and bi.products.id in (10)
and bi.valueAmount not in ('NA')
and ((bi.valueType = 'ACHIEVED' and bi.referenceYears.id = 1) or (bi.valueType = 'FINAL_BALANCE' and bi.referenceYears.id = 2))
group by bi.informationOwners.id
) MYTABLE
The compiler reports:
org.hibernate.hql.ast.QuerySyntaxException: unexpected token: ( near line 1, column 34
Do you have any idea what's wrong with the query? I tested the inner query and it works fine.
Thanks,
C
HQL subqueries can occur only in the select or where clauses, not FROM.