473,396 Members | 1,706 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,396 software developers and data experts.

Syntax Error in SQL Statement

675 512MB
The SQL statement:
Expand|Select|Wrap|Line Numbers
  1. SELECT tTitles.FKey FROM tTitles INNER JOIN tTitles ON (SELECT [ptr->tAAA] FROM tTitles WHERE (((Title) Like "*John*"))) = [ptr->tAAA]
produces the error
Syntax error. in query expression '(SELECT tTitles.Key FROM tTitles INNER JOIN tTitles ON (SELECT DISTINCT [ptr->tAAA] FROM tTitles WHERE (((Title) Like "*John*"))) = [ptr->tAAA]'.
Because I can run the query
Expand|Select|Wrap|Line Numbers
  1. SELECT DISTINCT [ptr->tAAA] FROM tTitles WHERE (((Title) Like "*John*"))
by itself, I assume that this isn't really a syntax error. What's going on?
Jul 20 '09 #1

✓ answered by ajalwaysus

Try This,

Expand|Select|Wrap|Line Numbers
  1. SELECT tTitles.FKey 
  2. FROM tTitles
  3. WHERE tTitles.[ptr->tAAA] IN (SELECT [ptr->tAAA] FROM tTitles WHERE Title Like "*John*")
Or Try,

Expand|Select|Wrap|Line Numbers
  1. SELECT tTitles.FKey 
  2. FROM tTitles INNER JOIN (SELECT [ptr->tAAA] FROM tTitles WHERE Title Like "*John*") AS ALIAS1 on tTitles.[ptr->tAAA] = ALIAS1.[ptr->tAAA]

5 1756
MikeTheBike
639 Expert 512MB
@OldBirdman
Hi

As far as I am aware the first SQL is not a valid query. It is also unclear as to what you are trying to achive, for instance if this doesn't do what you want, what is wrong with it ??
Expand|Select|Wrap|Line Numbers
  1. SELECT tTitles.FKey FROM tTitles WHERE (((Title) Like "*John*"))
With an answer to this we may be able to help !

MTB
Jul 21 '09 #2
ChipR
1,287 Expert 1GB
I don't think you can't compare the results of a SELECT with a singular value, unless you SELECT TOP 1.
Jul 21 '09 #3
OldBirdman
675 512MB
It is also unclear as to what you are trying to achive, for instance if this doesn't do what you want, what is wrong with it ??
This does exactly what I want. Or it would if it didn't get a syntax error. What is wrong with it is it won't execute because of a syntax error. I know it will do as I want because I can remove the subquery and create a 2nd query, and save it. I can now replace the subquery with the name of the saved query, and it works as I want.

As far as I am aware the first SQL is not a valid query.
Why not?
Jul 21 '09 #4
ajalwaysus
266 Expert 100+
Try This,

Expand|Select|Wrap|Line Numbers
  1. SELECT tTitles.FKey 
  2. FROM tTitles
  3. WHERE tTitles.[ptr->tAAA] IN (SELECT [ptr->tAAA] FROM tTitles WHERE Title Like "*John*")
Or Try,

Expand|Select|Wrap|Line Numbers
  1. SELECT tTitles.FKey 
  2. FROM tTitles INNER JOIN (SELECT [ptr->tAAA] FROM tTitles WHERE Title Like "*John*") AS ALIAS1 on tTitles.[ptr->tAAA] = ALIAS1.[ptr->tAAA]
Jul 21 '09 #5
OldBirdman
675 512MB
ajalwaysus - Both of your code samples worked correctly in my project. I have been testing these, and some new ideas of my own.
The first code
Expand|Select|Wrap|Line Numbers
  1. SELECT tTitles.FKey  
  2. FROM tTitles 
  3. WHERE tTitles.[ptr->tAAA] IN 
  4.     (SELECT [ptr->tAAA] 
  5.     FROM tTitles 
  6.     WHERE Title Like "*John*") 
  7.  
slows down appreciably when the tables become large. I suspect that the "IN" feature doesn't like 10K+ items.

The second code
Expand|Select|Wrap|Line Numbers
  1. SELECT tTitles.FKey  
  2.     FROM tTitles INNER JOIN (SELECT [ptr->tAAA] 
  3.     FROM tTitles WHERE Title Like "*John*") AS ALIAS1 
  4.     on tTitles.[ptr->tAAA] = ALIAS1.[ptr->tAAA] 
  5.  
needs aliases, whereas using a saved query does not. This was the key I needed. Following up on this idea, I find that expanding this to use in my project required each item selected in the subQuery also must have an alias. So the subQuery becomes
Expand|Select|Wrap|Line Numbers
  1. SELECT tAAA.Field1 AS F1, tAAA.Field2 AS F2, ....... 
  2.     FROM tAAA INNER JOIN ...... 
  3.     WHERE ...
  4.  
Then the query, as a general case, becomes
Expand|Select|Wrap|Line Numbers
  1. SELECT qry.F2, qry.F1, ... 
  2.     FROM 
  3.         (SELECT tAAA.Field1 AS F1, tAAA.Field2 AS F2, ....... 
  4.             FROM tAAA INNER JOIN ...... 
  5.             WHERE ...) as qry 
  6.     WHERE ([conditions]) 
  7.     ORDER BY Fn1, Fn2, ...
Mike - For, lets say, an Address Book, a record in tAddrBk would contain data about an individual or company. The name might be Robert Kennedy or Oakland Auto Repair, stored in another table, tNames. Also in tNames are alternate names, such as Bobby Kennedy or "Ken", the mechanic and owner of Oakland Auto. Searching for Bobby or Ken needs to find the alternate names, but display the primary names. tNames has a field Alt (Y/N). Therefore, your suggestion does not solve my problem.
Jul 23 '09 #6

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

Similar topics

3
by: Robert Mark Bram | last post by:
Hi All! I have the following two methods in an asp/jscript page - my problem is that without the update statement there is no error, but with the update statement I get the following error: ...
29
by: shank | last post by:
1) I'm getting this error: Syntax error (missing operator) in query expression on the below statement. Can I get some advice. 2) I searched ASPFAQ and came up blank. Where can find the "rules"...
7
by: Dave | last post by:
I have 2 tables, one with names, and another with addresses, joined by their CIVICID number (unique to the ADDRESSINFO table) in Oracle. I need to update a field in the NAMEINFO table for a...
7
by: kosta | last post by:
hello! one of my forms communicates with a database, and is supposed to add a row to a table using an Insert statement... however, I get a 'oledb - syntax error' exception... I have double...
3
by: Nathan Sokalski | last post by:
When trying to submit data to an Access database using ASP.NET I recieve the following error: System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(Int32 hr) +41...
1
by: amitbadgi | last post by:
HI i am getting the foll error while conv an asp application to asp.net Exception Details: System.Runtime.InteropServices.COMException: Syntax error in UPDATE statement. Source Error: Line...
5
by: amitbadgi | last post by:
Hi guys, I am getting the following error in teh insert statement , I am converting this asp application to asp.net, here is teh error, Exception Details:...
7
by: Csaba Gabor | last post by:
I feel like it's the twilight zone here as several seemingly trivial questions are bugging me. The first of the following three lines is a syntax error, while the last one is the only one that...
12
by: Brad Baker | last post by:
I am trying to write a simple ASP.net/C# page which allows users to select some values and produce a report based on a SQL query. I have a self posting dropdown form which allows users to select...
1
by: ajos | last post by:
hi evrybdy, the problem is:- i had this running before in jsp but when i changed the jsp page using struts tags there occoured a problem... when i enter values in the 2 text boxes and click enter...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.