Incorrect column expression

H

Hugh Mungo

Hi,

I get the following error
Incorrect column expression: 'sum(case when month(acc_Date)=1 then 1 else 0
end)'.
When I try and run the following SQL in excel 'Get External Data' - however
when run directly in SQL Server it works fine.
Any ideas about what could be wrong?
SELECT
dept,
Jan = sum(case when month(acc_Date)=1 then 1 else 0 end),
Feb = sum(case when month(acc_Date)=2 then 1 else 0 end),
Mar = sum(case when month(acc_Date)=3 then 1 else 0 end),
Apr = sum(case when month(acc_Date)=4 then 1 else 0 end),
May = sum(case when month(acc_Date)=5 then 1 else 0 end),
Jun = sum(case when month(acc_Date)=6 then 1 else 0 end),
Jul = sum(case when month(acc_Date)=7 then 1 else 0 end),
Aug = sum(case when month(acc_Date)=8 then 1 else 0 end),
Sep = sum(case when month(acc_Date)=9 then 1 else 0 end),
Oct = sum(case when month(acc_Date)=10 then 1 else 0 end),
Nov = sum(case when month(acc_Date)=11 then 1 else 0 end),
Dec = sum(case when month(acc_Date)=12 then 1 else 0 end)
FROM incident
WHERE (acc_date BETWEEN '01-01-2004' AND '31-12-2004')
GROUP BY dept
 

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