Column aliases use literal not alias in Group By

N

NickB

This query creates two columns with aliases and a literal as the value. It
works fine in Access but falls over when using a table linked to SQL Server
because the generated SQL uses the literal as the column name not the alias
(see below). I have tried using column number (ie group by 1,3) but this
doesn't make any difference. Also tried editing the SQL to use the aliases
but it won't run at all then.

Same symptoms under ANSI 89 and 92.

********************************
SELECT "040 - ServiceContracts" AS Status,
Count(dbo_viewServiceContractFull.ClientCode) AS [Number], "" AS Report
FROM dbo_viewServiceContractFull
GROUP BY "040 - ServiceContracts", "";
********************************
 
D

Douglas J. Steele

Try it without the GROUP BY clause. Since both are constants, it shouldn't
be necessary.

SELECT "040 - ServiceContracts" AS Status,
Count(dbo_viewServiceContractFull.ClientCode) AS [Number], "" AS Report
FROM dbo_viewServiceContractFull
 
N

NickB

Douglas,

That fixed it. Edited the SQL but noticed that this replaces "Group By"
with "Expression" on the query designer. Thanks.

--
NickB


Douglas J. Steele said:
Try it without the GROUP BY clause. Since both are constants, it shouldn't
be necessary.

SELECT "040 - ServiceContracts" AS Status,
Count(dbo_viewServiceContractFull.ClientCode) AS [Number], "" AS Report
FROM dbo_viewServiceContractFull


--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


NickB said:
This query creates two columns with aliases and a literal as the value.
It
works fine in Access but falls over when using a table linked to SQL
Server
because the generated SQL uses the literal as the column name not the
alias
(see below). I have tried using column number (ie group by 1,3) but this
doesn't make any difference. Also tried editing the SQL to use the
aliases
but it won't run at all then.

Same symptoms under ANSI 89 and 92.

********************************
SELECT "040 - ServiceContracts" AS Status,
Count(dbo_viewServiceContractFull.ClientCode) AS [Number], "" AS Report
FROM dbo_viewServiceContractFull
GROUP BY "040 - ServiceContracts", "";
********************************
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top