View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.links
rachael
 
Posts: n/a
Default can't change field name in query?

Sorry - i don't think i was clear. The line i posted was just a fragment. The
full code works, and i do get a field back that shows the proper count. The
problem is, the field has no name, even if i include "AS NewName". If i run
the same SQL in Access, i get a field back with the proper count that has a
field name of "NewName."

Is this just a quirk in MS Query in Excel that i'm not getting back a field
name? Or is there something else i need to do?

Thanks
rachael

"Ed Ferrero" wrote:

Hi rachael,

You need to add a Group By clause to use the COUNT function in SQL

Try something like this example (uses Northwind)

SELECT Customers.Country, Customers.Region, Count(Customers.Region) AS
CountStatus
FROM master.dbo.Customers Customers

Ed Ferrero
http://www.edferrero.com


"rachael" wrote in message
...
I'm using Microsoft Query to bring in some data. I have the query in SQL
so i
can do some groupings and count values in one of the fields. My problem is
I'm having difficulty renaming a field, so it comes back with no name at
all.
The SQL line is:

SELECT [lots of fields], Count(StudentHistory.Status) AS CountStatus

The count comes back properly, but the changed field name (i.e.,
CountStatus) doesn't appear. The field name is blank. How does this need
to
be written so the field name comes back as CountStatus?

Thanks
rachael