Discussion
Can someone tell me why I keep getting a syntax error when I try to run this query?
SELECT kpm.kpm_code AS Code, SUM(kpm.kpm_standard*(1000/kpm.kpm_weight)) AS Cost
FROM kpm kpm
WHERE (kpm.kpm_locn<>'FAIL') AND (kpm.kpm_stop<>'S')
I've only been fiddling with SQL since yesterday afternoon and I'm in a bit of a muddle!
SELECT kpm.kpm_code AS Code, SUM(kpm.kpm_standard*(1000/kpm.kpm_weight)) AS Cost
FROM kpm kpm
WHERE (kpm.kpm_locn<>'FAIL') AND (kpm.kpm_stop<>'S')
I've only been fiddling with SQL since yesterday afternoon and I'm in a bit of a muddle!
spitfire-ian said:
Can someone tell me why I keep getting a syntax error when I try to run this query?
SELECT kpm.kpm_code AS Code, SUM(kpm.kpm_standard*(1000/kpm.kpm_weight)) AS Cost
FROM kpm kpm
WHERE (kpm.kpm_locn<>'FAIL') AND (kpm.kpm_stop<>'S')
I've only been fiddling with SQL since yesterday afternoon and I'm in a bit of a muddle!
SELECT kpm.kpm_code AS Code, SUM(kpm.kpm_standard*(1000/kpm.kpm_weight)) AS Cost
FROM kpm kpm
WHERE (kpm.kpm_locn<>'FAIL') AND (kpm.kpm_stop<>'S')
I've only been fiddling with SQL since yesterday afternoon and I'm in a bit of a muddle!
You don't say what flavour of SQL, but smells a bit like MSSQL to me...
First, what is the actual unabridged error?
Secondly, simplify - rewrite as
SELECT kpm_code AS Code, SUM(kpm_standard*(1000/kpm_weight)) AS Cost
FROM kpm
WHERE (kpm_locn<>'FAIL') AND (kpm_stop<>'S')
although I suspect the "SUM" is causing grief.
Ciao
Zak
spitfire-ian said:
zaktoo said:
You don't say what flavour of SQL, but smells a bit like MSSQL to me...
The code is produced by MS Query so I guess it must be.
zaktoo said:
First, what is the actual unabridged error?
All I get is syntax error
As Jamieboy says you're probably missing the group by clause or sum is not doing what you expect.
I'd also enclose the division bit with a test for the divisor being 0 and returning null if it is, continuing with the formula if no, once you've got a hold of the actual syntactical error.
HTH
Ciao
Zak
I took what Grumbledoak and Jamieboy said and have come up with
SELECT kpm_code AS Code, 1000 * SUM(kpm_standard / kpm_weight) AS Cost
FROM kpm
WHERE (kpm_locn<>'FAIL') AND (kpm_stop<>'S')
GROUP BY kpm-code
Is that right?
It now gives me an error saying cannot find kpm in any local table
SELECT kpm_code AS Code, 1000 * SUM(kpm_standard / kpm_weight) AS Cost
FROM kpm
WHERE (kpm_locn<>'FAIL') AND (kpm_stop<>'S')
GROUP BY kpm-code
Is that right?
It now gives me an error saying cannot find kpm in any local table
spitfire-ian said:
I took what Grumbledoak and Jamieboy said and have come up with
SELECT kpm_code AS Code, 1000 * SUM(kpm_standard / kpm_weight) AS Cost
FROM kpm
WHERE (kpm_locn<>'FAIL') AND (kpm_stop<>'S')
GROUP BY kpm-code
Is that right?
It now gives me an error saying cannot find kpm in any local table
SELECT kpm_code AS Code, 1000 * SUM(kpm_standard / kpm_weight) AS Cost
FROM kpm
WHERE (kpm_locn<>'FAIL') AND (kpm_stop<>'S')
GROUP BY kpm-code
Is that right?
It now gives me an error saying cannot find kpm in any local table
that's GROUP BY kpm_code
spitfire-ian said:
I took what Grumbledoak and Jamieboy said and have come up with
SELECT kpm_code AS Code, 1000 * SUM(kpm_standard / kpm_weight) AS Cost
FROM kpm
WHERE (kpm_locn<>'FAIL') AND (kpm_stop<>'S')
GROUP BY kpm-code
Is that right?
It now gives me an error saying cannot find kpm in any local table
the text you've put here has 'GROUP BY kpm-code' not 'GROUP BY kpm_code' - not sure if that's a typo here or in your query. SELECT kpm_code AS Code, 1000 * SUM(kpm_standard / kpm_weight) AS Cost
FROM kpm
WHERE (kpm_locn<>'FAIL') AND (kpm_stop<>'S')
GROUP BY kpm-code
Is that right?
It now gives me an error saying cannot find kpm in any local table
spitfire-ian said:
Sorry, that was a typo by me.
Back to our old friend the syntax error again.
Back to our old friend the syntax error again.
you doing this in MSQuery from Excel?
If so I suspect you problem might be that MSQuery doesn't like the construct
select a As b
it will replace b with blank
so if you have
select a AS b, c AS d
it will have 2 blanks which may throw the error.
try removing one of the AS bits.
Gassing Station | Computers, Gadgets & Stuff | Top of Page | What's New | My Stuff


