I´ve been trying to find the error in this statement for a few hours and can´t seem to find it.
It must have something to do with the AND connecting the two WHERE´s since when deleting the first WHERE it works:
SELECT E_AUFMASS_KOMMENTARE.FIBU_FIRMA,
E_AUFMASS_KOMMENTARE.AUFTR_NR,
E_AUFMASS_KOMMENTARE.KOMMENTAR,
AUFTR_EXT.ART_GRUPPE
FROM HHNG_AU.E_AUFMASS_KOMMENTARE
INNER JOIN HHNG_AU.AUFTR_EXT ON E_AUFMASS_KOMMENTARE.AUFTR_NR = AUFTR_EXT.AUFTR_NR
WHERE (E_AUFMASS_KOMMENTARE.AUFTR_NR = '1248823' )
AND WHERE NOT EXISTS( SELECT * FROM HHNG_AU.EX_KOMMENTARE WHERE EX_KOMMENTARE.AUFTR_NR = '1248823' )
Too many WHERE. You only need where once, then use ANDs and ORs to combine conditions:
SELECT E_AUFMASS_KOMMENTARE.FIBU_FIRMA, E_AUFMASS_KOMMENTARE.AUFTR_NR, E_AUFMASS_KOMMENTARE.KOMMENTAR, AUFTR_EXT.ART_GRUPPE FROM HHNG_AU.E_AUFMASS_KOMMENTARE INNER JOIN HHNG_AU.AUFTR_EXT ON E_AUFMASS_KOMMENTARE.AUFTR_NR = AUFTR_EXT.AUFTR_NR WHERE (E_AUFMASS_KOMMENTARE.AUFTR_NR = '1248823' ) AND NOT EXISTS( SELECT * FROM HHNG_AU.EX_KOMMENTARE WHERE EX_KOMMENTARE.AUFTR_NR = '1248823' )
Related
SELECT p.pnum, p.pname
FROM professor p, class c
WHERE p.pnum = c.pnum AND c.cnum = CS245 AND (SELECT COUNT(*) FROM (SELECT MAX(m.grade), MAX(m.grade) - MIN(m.grade) AS diff
FROM mark m WHERE m.cnum = c.cnum AND m.term = c.term AND m.section = c.section AND diff <= 20)) = 3
Incorrect syntax near ')'. Expecting AS, FOR_PATH, ID, or QUOTED_ID.
Consider the following example:
SELECT COUNT(1)
FROM SYSCAT.TABLES T
WHERE
(
-- SELECT COUNT(1)
-- FROM
-- (
SELECT COUNT(1)
FROM SYSCAT.COLUMNS C
WHERE C.TABSCHEMA=T.TABSCHEMA AND C.TABNAME=T.TABNAME
-- )
) > 50;
The query above works as is. But the problem is, that if you uncomment the commented out lines, you get the following error message: "T.TABNAME" is an undefined name. and least in Db2 for Linux, Unix and Windows.
You can't push external to the sub-select column references too deeply.
So, your query is incorrect.
It's hard to correct it, until you provide the task description with data sample and the result expected.
I can see a potential syntax errors: It seems that CS245 refers to a value c.cnum may take and not a column name. If that is the case, it should be enclosed in single quotes.
Hello guys i am working on an query and every thing is working fine except when i run a query more than 2-3 times this return timeout is there is something wrong in my query or this is server error kindly suggest me here is my query
SELECT
Category_Feature_Mapping.Feature_ID,
Category_Feature_Mapping.Category_ID,
Option_Table.Option_ID,
Option_Table.Title,
Feature_Table.Title AS featuretitle,
Feature_Table.Type
FROM
Category_Feature_Mapping
INNER JOIN Feature_Table
ON Category_Feature_Mapping.Feature_ID = Feature_Table.Feature_ID
INNER JOIN Option_Table
ON Feature_Table.Feature_ID = Option_Table.Feature_ID
WHERE
Category_Feature_Mapping.Category_ID = #catid
AND Feature_Table.Feature_ID=#feid
AND Feature_Table.Feature_ID not in (SELECT
Feature_ID
FROM
Vendor_Value_Table
WHERE
Vendor_ID=#venid)
GROUP BY
Category_Feature_Mapping.Feature_ID,
Category_Feature_Mapping.Category_ID,
Option_Table.Option_ID,
Option_Table.Title,
Feature_Table.Title,
Feature_Table.Type
try to append ";Connection Timeout=100" to you connectionstring for up your timeout
may by a question of performance, try to replace "not in" by "not exists" like this
AND not exists (
SELECT * FROM Vendor_Value_Table vvt
WHERE Feature_Table.Feature_ID =vvt.Feature_ID and vvt.Vendor_ID=#venid
)
I am having an issue with my SELECT query. I am trying to find items that do not start with "50700" and have an enabled flag of 1, are in category 4 and sub category 4. Below is the query i have but it is not returning any results when i know there are some. Please note TBL1.FIELD1 = ITM_ID, TBL1.FIELD2 = ENABLED, TBL2.FIELD1 = CAT_ID, TBL2.FIELD2 = SUBCAT_ID.
SELECT DB_NAME.dbo.TBL1.FIELD1
, DB_NAME.dbo.TBL1.FIELD2
, DB_NAME.dbo.TBL2.FIELD1
, DB_NAME.dbo.TBL2.FIELD2
FROM DB_NAME.dbo.TBL1
, DB_NAME.dbo.TBL2
WHERE DB_NAME.dbo.TBL1.FIELD1 NOT LIKE '50700%'
AND DB_NAME.dbo.TBL1.FIELD2 = 1
AND DB_NAME.dbo.TBL2.FIELD1 = 4
AND DB_NAME.dbo.TBL2.FIELD2 = 4
You can break the query into different subqueries for debug purpose, this way you can figure out which "AND" condition is not working.
For Example:
Firstly I guess you should try a simple query on TBL1.FIELD1 with the simple query :
select TBL1.FIELD1 from DB_NAME.dbo.TBL1 where DB_NAME.dbo.TBL1.FIELD1 NOT LIKE '50700' ;(*if TBL1.FIELD1 is of String type, else go for TBL1.FIELD1 != 50700 * )
Then if you get results ,try to do "AND" with the TBL1.FIELD2 condition.
select TBL1.FIELD1
from DB_NAME.dbo.TBL1
where DB_NAME.dbo.TBL1.FIELD1 NOT LIKE '50700'
and DB_NAME.dbo.TBL1.FIELD2 =4 ;
This way you can proceed further and debug the query. Hope it helps :)
I'm trying to execute the following query in Oracle:
SELECT c.id_cliente, c.nombre_cliente, c.apellidos_cliente
FROM cliente c
WHERE not exists (SELECT f.id_finca
FROM finca f
WHERE f.habitaciones = 3
EXCEPT
SELECT v.id_fincas
FROM visitas v
WHERE v.id_cliente = c.id_cliente)
But I am getting the error "missing right parenthesis".
The parenthesis are well-balanced, how can I solve this error?
Use MINUS instead of EXCEPT.
SELECT c.id_cliente,
c.nombre_cliente,
c.apellidos_cliente
FROM cliente c
WHERE NOT EXISTS (SELECT f.id_finca
FROM finca f
WHERE f.habitaciones = 3
MINUS
SELECT v.id_fincas
FROM visitas v
WHERE v.id_cliente = c.id_cliente)
there is no operator EXCEPT in Oracle. Use MINUS instead of it.
Additionally, your query seems weird: better try to make it with two not exists, I think it can give some performance.
Been trying to get the following query working for a few hours now and am running out of ideas. Can anyone spot where I'm going wrong. Any pointers much appreciated.
CalEvents = (List<CalEvent>)session.CreateSQLQuery(#"
SELECT *
FROM dbo.tb_calendar_calEvents
INNER JOIN dbo.tb_calEvents
ON (dbo.tb_calendar_calEvents.calEventID = dbo.tb_calEvents.id)
WHERE dbo.tb_calendar_calEvents.calendarID = 'theCalID'"
)
.AddEntity(typeof(CalEvent))
.SetInt64("theCalID", cal.id);
Error:
Kanpeki.NUnit.CalUserTest.Should_return_logged_in_user:
System.ArgumentException : Parameter theCalID does not exist as a
named parameter in [SELECT * FROM dbo.tb_calendar_calEvents INNER JOIN
dbo.tb_calEvents ON (dbo.tb_calendar_calEvents.calEventID =
dbo.tb_calEvents.id) WHERE dbo.tb_calendar_calEvents.calendarID =
'theCalID']
"SELECT * FROM dbo.tb_calendar_calEvents INNER JOIN dbo.tb_calEvents ON (dbo.tb_calendar_calEvents.calEventID = dbo.tb_calEvents.id) WHERE dbo.tb_calendar_calEvents.calendarID = 'theCalID'"
should be
"SELECT * FROM dbo.tb_calendar_calEvents INNER JOIN dbo.tb_calEvents ON (dbo.tb_calendar_calEvents.calEventID = dbo.tb_calEvents.id) WHERE dbo.tb_calendar_calEvents.calendarID = :theCalID"
= 'theCalID' should be written as = :theCalId; :theCalId is how you use named parameters even in Native SQL Queries.
You should remove the query.ExecuteUpdate() call.
Doing the query.List() is enough to issue the query on the session and return the result set.