Q: SQl , multiple questions ( parameters in a join and putting a column into a row I am trying to group a table by date (mm/yyyy) and then by invoicetype, I have tried putting in the code below but I keep getting the error 'invalid column date'.
SELECT RIGHT(CONVERT(VARCHAR(10), case_createddate, 103), 7) AS Date,
       case_invoicetype,
       Sum(case_totalexvat)
FROM   cases AS ca
WHERE  case_primaryCompanyid = 1111
GROUP  BY ca.Date,
          case_invoicetype 

I tried this:
group by YEAR(case_createddate), MONTH(case_createddate)

But I get the error:

case_createddate is invalid in the select list because it is not
  contained in either an aggregate function or the group by clause

Any ideas ?
Thanks

A: Use the GROUP BY clause on the whole expression
SELECT RIGHT(CONVERT(VARCHAR(10), case_createddate, 103), 7) AS Date,
       case_invoicetype,
       Sum(case_totalexvat)
FROM   cases AS ca
WHERE  case_primaryCompanyid = 1111
GROUP  BY RIGHT(CONVERT(VARCHAR(10), case_createddate, 103), 7),
          case_invoicetype 


A: You need to include all non aggregated columns from the select in the group by clause. ca.Date is not in the select, I suspect you want this:
SELECT RIGHT(CONVERT(VARCHAR(10), case_createddate, 103), 7) AS Date,
       case_invoicetype,
       Sum(case_totalexvat)
FROM   cases AS ca
WHERE  case_primaryCompanyid = 1111
GROUP  BY RIGHT(CONVERT(VARCHAR(10), case_createddate, 103), 7),
          case_invoicetype 

