Hi allI'm having real problems here! I've read around plenty and just can't work this out. My Group By clause is being rejected if I include an either the column definition or the column name!DECLARE @OnDay datetimeSET @OnDay = '20080131'select datename(month, @OnDay) as 'MonthName', count(*) as 'Total'from memberswhere isnull(substype, '') <> ''and (leavedate is null or leavedate >= @OnDay)and (joindate < @OnDay and isnull(joindate, '') <>'')group by datename(month, @OnDay)
If I do it like the above the error is that I must use a column name in the group by clause, or if I do the following...group by 'MonthName'
...it complains that the column name has to be in the select list - even though it clearly is!Where am I going wrong??