473,508 Members | 2,008 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SQL Statement Mystery

Hi all,

I have a statement that reads as follows:
select [Sales Ledger] - gl as difference
from
(SELECT SUM(RPAAP / 100) AS [Sales Ledger] FROM F03B11) Q1
join
(SELECT SUM(GBAPYC + GBAN01 + GBAN02 + GBAN03 + GBAN04 + GBAN05 +
GBAN06
+ GBAN07 + GBAN08 + GBAN09 + GBAN10 + GBAN11 + GBAN12)/100
AS GL
FROM F0902
WHERE (GBAID = '00667809') AND (GBFY = 3)) Q2

My first nested statement however I keep getting the message:
Server: Msg 170, Level 15, State 1, Line 8
Line 8: Incorrect syntax near 'Q2'.

I just cannot fathom why this is so?

Any suggestions would be most helpful.
Moby


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #1
1 1962
The syntax error was caused by the fact that you had missed the ON clause.
An inner join must have an ON clause.

In fact you don't need a join at all:

SELECT
(SELECT SUM(RPAAP)
FROM F03B11)/100.0
-
(SELECT SUM(GBAPYC +
GBAN01 + GBAN02 + GBAN03 + GBAN04 +
GBAN05 + GBAN06 + GBAN07 + GBAN08 +
GBAN09 + GBAN10 + GBAN11 + GBAN12)
FROM F0902
WHERE GBAID = '00667809' AND GBFY = 3)/100.0

Note the change to the division sums. Your original query would have caused
an integer division which loses precision in the result.

--
David Portas
------------
Please reply only to the newsgroup
--

"Sam G" <mo**@spamhole.com> wrote in message
news:3f*********************@news.frii.net...
Hi all,

I have a statement that reads as follows:
select [Sales Ledger] - gl as difference
from
(SELECT SUM(RPAAP / 100) AS [Sales Ledger] FROM F03B11) Q1
join
(SELECT SUM(GBAPYC + GBAN01 + GBAN02 + GBAN03 + GBAN04 + GBAN05 +
GBAN06
+ GBAN07 + GBAN08 + GBAN09 + GBAN10 + GBAN11 + GBAN12)/100
AS GL
FROM F0902
WHERE (GBAID = '00667809') AND (GBFY = 3)) Q2

My first nested statement however I keep getting the message:
Server: Msg 170, Level 15, State 1, Line 8
Line 8: Incorrect syntax near 'Q2'.

I just cannot fathom why this is so?

Any suggestions would be most helpful.
Moby


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1754
by: William Wisnieski | last post by:
Hello Everyone: I'm having a very strange problem occurring with my Access 2000 database. I call it the "mystery record." Here's the story: I have a query by form that returns a record set...
115
7473
by: Mark Shelor | last post by:
I've encountered a troublesome inconsistency in the C-language Perl extension I've written for CPAN (Digest::SHA). The problem involves the use of a static array within a performance-critical...
14
2753
by: jojoba | last post by:
Hi, I hope this post is ok for this group. Here's my deal: I have two computers on my LAN at home. One desktop. One laptop. Both computers are wireless enabled (and wired enabled too). I...
5
32077
by: Jack | last post by:
Is there anyway in SQL Server to rollback an SQL statement which was already executed. I know there is a transaction log but what it contains and how it works is still a mystery to me. Assuming I...
8
2841
by: Rick | last post by:
I am new to ASP.NET I have worked many years in Coldfusion. I am having a problem finding out how to put an IF Statement into the HTML. How do I do this in ASP.NET? Thanks for any help you can...
1
1455
by: keri | last post by:
I want my code to change the back colour to red (of a form field) if the name is either "admin" or "meeting" or "holiday". I tried this; If rs!ACCOUNTNAME = "Meeting" Then f("text" &...
0
973
by: jasonswett | last post by:
I'm looking at a C++ program written by someone else that has the following line: sql.replace( "select name(char51) into :name: from group where tech_id=" ); The SQL statement has a value...
1
4176
by: ARC | last post by:
Ok, this is strange. I created a new database and imported all objects from the old program file. Form some reason, the option explicit statement is no longer showing in my code modules (and I...
7
3229
by: Arun Srinivasan | last post by:
I have a problem, I am getting SQL1042N The SQL statement is not supported. error when I try to create a MQT against a nickname. The source db is db2 version 9.1 fixpack 4, same as the target db...
0
7127
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
7391
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
5633
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,...
1
5056
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
4713
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3204
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3188
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1564
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
768
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.