473,378 Members | 1,142 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Incorrect syntax near the keyword 'EXISTS'.

syedshaffee
Hey people,
i am getting this error 'Incorrect syntax near the keyword 'EXISTS'.'
while executing this query
Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT Contract_detail.Contract_no
  3. FROM   Contract_detail INNER JOIN ContractRewriteHistory ON Contract_detail.Contract_no = ContractRewriteHistory.ContractNo
  4. WHERE Contract_detail.Contract_no  NOT EXISTS
  5. (
  6. SELECT ContractNo FROM ContractRewriteHistory WHERE 
  7. ContractNo<>'' AND
  8. ContractRewriteHistory.ContractNo = Contract_detail.Contract_no
  9. );
  10.  
  11.  
Please tell me what is wrong in this
Oct 16 '12 #1

✓ answered by Rabbit

The EXISTS and NOT EXISTS isn't a comparison against a column. You use IN or NOT IN to compare against a column.

However, you should use neither. The current query you are attempting to use will return 0 rows. If your goal is to find contracts in detail that are not in rewrite history, that is not the correct way to go about it. You should use an outer join query and filter for the nulls.

3 4359
debasisdas
8,127 Expert 4TB
try this

Expand|Select|Wrap|Line Numbers
  1. SELECT Contract_detail.Contract_no
  2. FROM   Contract_detail INNER JOIN ContractRewriteHistory ON Contract_detail.Contract_no = ContractRewriteHistory.ContractNo
  3. WHERE NOT EXISTS
  4. (
  5. SELECT ContractNo FROM ContractRewriteHistory WHERE 
  6. ContractNo<>'' AND
  7. ContractRewriteHistory.ContractNo = Contract_detail.Contract_no
  8. );
Oct 16 '12 #2
Rabbit
12,516 Expert Mod 8TB
The EXISTS and NOT EXISTS isn't a comparison against a column. You use IN or NOT IN to compare against a column.

However, you should use neither. The current query you are attempting to use will return 0 rows. If your goal is to find contracts in detail that are not in rewrite history, that is not the correct way to go about it. You should use an outer join query and filter for the nulls.
Oct 16 '12 #3
Thanx rabbit you rock
Oct 17 '12 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Jeff Magouirk | last post by:
Dear Group, I am trying to create a view and keep getting the Incorrect syntax near the keyword 'Declare'" error. Here is the code I am writing. Create view fixed_airs (sid, fad_a2, fad_a3)...
2
by: JMUApache | last post by:
Hi, I have got a error message while I run a sample OLEDB program. It says "Incorrect Syntax Near The Keyword Default Information". platform: Windows XP + Visual Studio 2005 Beta 2 + SQL...
2
by: Jon | last post by:
hi, i was trying to create a DB in a SQL Server. but when i try to connect it with : Dim conn As SqlConnection = New SqlConnection("Initial Catalog=master; " & _ "Data Source=SERVER-MACHINE;" &...
1
by: Sandesh | last post by:
Hello All, Me saying " has any body come across such error would be underestimating". Well I am getting a very peculiar and unique error "Line 1: Incorrect syntax near 'Actions'." ...
2
by: ielmrani via SQLMonster.com | last post by:
Hi Everyone, I really tried to not post this question but I gave up. I tried brackets, parenth...etc but nothing worked. I get this error message: Incorrect syntax near the keyword 'THEN'. ...
0
by: netone | last post by:
I am developing site using dot NET.... when I use this sql query Dim mydata As String = "SELECT director.applno, district.distName, disabappl.recvddate_sdo, disabappissue.IDCardNo,...
10
by: arial | last post by:
Hi, I am getting this error message: Incorrect syntax near the keyword 'where'. Description: An unhandled exception occurred during the execution of the current web request. Please review...
1
by: karenkksh | last post by:
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. ...
43
by: dougancil | last post by:
Can someone please review my code and see where I can be missing information. I get the following error: Line 1: Incorrect syntax near ','. Unclosed quotation mark before the character string '...
5
NeoPa
by: NeoPa | last post by:
As the title implies, I am getting the following error message with some SQL I'm trying to use. I'm using MS Management Studio 2008 with a link to a 2005 server. What confuses me is that when I...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.