Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sql mathematic statements

Status
Not open for further replies.

crymedry

MIS
Nov 19, 2003
54
0
0
Hello All:

I have a question and will welcome any help. I have a database that has a list of accounts and values in those accounts. we judge our different sites on this dollar value. I am passing a value from one page to the next, which works fine, but I get an error on my SELECT statement. It is as follows:

GPA = "SELECT *, SUM(CLOSE $) as totclose, SUM(OPEN RES) as totopen, SUM(ADJ FEE) as totadj WHERE OFFICE='"& location&"'"

the location varible is the one passed from the previous page. I get an error on the first SUM statement.

Thank you for any help!

Kris
 
try this:

Code:
GPA = "SELECT *, SUM([CLOSE $]) as totclose, SUM([OPEN RES]) as totopen, SUM([ADJ FEE]) as totadj WHERE OFFICE='"& location&"'"

-DNG
 
Ok ... I tried that, and now I am getting a:

Syntax error (missing operator) in query expression 'WHERE OFFICE='CB''

the post data is being carried over ... should I do multiple sql statements? Is the fact that the WHERE comes after the SUM statements?

Thanks again for the help.
 
From Table ??? [ponder]

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Your next error will problably mention something about aggregates without a group by....

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Hi,
Check the
WHERE OFFICE='"& location&"'" part..it looks like it is not being concatenated correctly..
Try:
WHERE OFFICE='" & location & "'"

( Really shouldn't matter about the spaces, but...)

[profile]

To Paraphrase:"The Help you get is proportional to the Help you give.."
 
no...spaces shouldnt be a problem Turkbear...i am thinking may be he needs to do use a replace() function to replace any single quotes...and also has George pointed out...there is no FROM clause in the query...

-DNG
 
OK .... I realized that there is not a FROM statement in there. I have changed it to:

GPA = "SELECT SUM([CLOSE $]) as totclose, SUM([OPEN RES]) as totopen, SUM([ADJ FEE]) as totadj FROM MASTER WHERE OFFICE='"& location &"'"

Now I get the error that:

The SELECT staement includes a reserved word or an argument name that is misspelled or missing, or the punctuation is incorrect.

I have looked and all my parentheses are closed and all quotes accounted for. What am I missing now?

THanks!!
 
try this:

Code:
GPA = "SELECT SUM([CLOSE $]) as totclose, SUM([OPEN RES]) as totopen, SUM([ADJ FEE]) as totadj FROM [MASTER] WHERE OFFICE='"& location &"'"

dont you want to do a group by office?
-DNG
 
Well I tried that and I get the same error.

I don't want to group by the office cause I'm trying to get the totals for each specific office. The first page of this they select what office to view, and then this page is supposed to pull all the data together and add all of it up.

any more ideas anyone?
 
Well, only one item left, might as well put some square brackets around the OFFICE field name also.
If it still complains then it is probably an issue with the $, you can test this by just taking he first sum out of your query and seeing if it returns a result.

I don't think you should get an aggregate error on this unless you put OFFICE in the SELECT portion of your query.

 
I tried cutting that out, I also tried putting the OFFICE in square brackets, same error.

The statement now looks like this:

GPA = "SELECT SUM([COSE $]) as totclose, SUM([OPEN RES]) as totopen, SUM([ADJ FEE]) as totadj, FROM [MASTER} WHERE [OFFICE]='"& location &"'"

The error that I get is:
The SELECT staement includes a reserved word or an argument name that is misspelled or missing, or the punctuation is incorrect.

I am at a loss, any help would be greatly appreciated!!!
 
Remove the comma after as totadj

You have a right curly bracket after MASTER. It should be a right square bracket.

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
K ... fixed the stupid mistakes .... now I have a "Too few parameters. Expected 1." error.

Here is what I have:
GPA = "SELECT SUM([CLOSE $]) as totclose, SUM([OPEN RES]) as totopen, SUM([ADJ FEE]) as totadj FROM [MASTE] WHERE [OFFICE]='"& location &"'"

Thanks again for the help!!
 
[MASTE] ???

I thought it was [MASTE[!]R[/!]]

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Sorry, that was a typo from me just typing it out and not cut and paste, it is [MASTER].

Do you see any operators or punctuation missing?
 
Is there anyway I can use a response.write statement somewhere to debug this script?

Thanks again!
 
yes before executing your query...you can do...

Response.write GPA

-DNG
 
It's possible a large amount of time would have been saved by reading
Development practices when using SQL/Interfaces faq333-4896
and in the future using the methods

[sub]____________ signature below ______________
The worst mistake you'll ever make is to do something simply the way you know how while ignoring the way it should be done[/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top