473,386 Members | 1,758 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,386 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 4362
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.