A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Subquery Syntax error



 
 
Thread Tools Display Modes
  #1  
Old July 10th, 2009, 03:05 AM posted to microsoft.public.access
dhstein
external usenet poster
 
Posts: 665
Default Subquery Syntax error

I'm trying to figure out how to do something - so I'm playing around with
this subquery and getting a syntax error.

SELECT tblInvoice.CustomerName
FROM tblInvoice INNER JOIN tblLines ON tblInvoice.InvoiceNumber =
tblLines.InvoiceNumber
(SELECT TOP 1 Dupe.CustomerName
FROM tblInvoice AS Dupe
WHERE Dupe.InvoiceNumber = tblInvoice.InvoiceNumber
ORDER BY Dupe.InvoiceDate DESC)
FROM tblInvoice;

Any help is appreciated
  #2  
Old July 10th, 2009, 03:56 AM posted to microsoft.public.access
Sylvain Lafontaine[_2_]
external usenet poster
 
Posts: 247
Default Subquery Syntax error

Not telling us what you are trying to do doesn't make the thing easier to
understand for us. Also, your subquery seems to be misplaced as it is
presently in the FROM part instead of beeing in the SELECT or the WHERE part
and the way it is, I absolutely don't understand what you are trying to
achieve.

The subquery is also missing an alias name; something which is always
mandatory for a subquery.

Finally, using a totally different name such as Dupe for renaming the table
Invoice in the subquery is calling for trouble for later when you'll try to
read back your code. You should use something easier to understand such as
Invoice2 or I2.

--
Sylvain Lafontaine, ing.
MVP - Windows Live Platform
Email: sylvain2009 sylvainlafontaine com (fill the blanks, no spam please)
Independent consultant and remote programming for Access and SQL-Server
(French)


"dhstein" wrote in message
...
I'm trying to figure out how to do something - so I'm playing around with
this subquery and getting a syntax error.

SELECT tblInvoice.CustomerName
FROM tblInvoice INNER JOIN tblLines ON tblInvoice.InvoiceNumber =
tblLines.InvoiceNumber
(SELECT TOP 1 Dupe.CustomerName
FROM tblInvoice AS Dupe
WHERE Dupe.InvoiceNumber = tblInvoice.InvoiceNumber
ORDER BY Dupe.InvoiceDate DESC)
FROM tblInvoice;

Any help is appreciated



 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 08:11 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.