October 19, 2012 at 11:29 am
Hi geniuses, I'm getting this error when I try to Sum all the values from a column:
SELECT DISTINCT Cap, Sum(Value)
FROM AnalysisTABS
WHERE (Cap <> '') AND (valueType = '03 - DLP')
ERROR MESSAGE:
is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Solutions?
Thanks
October 19, 2012 at 11:36 am
You need to add the 'group by CAP' and remove the 'distinct'.
October 19, 2012 at 11:53 am
Thanks Body!
October 19, 2012 at 12:53 pm
You might also consider changing your where clause so you can avoid the index scan on Cap. Change the condition to greater than and you should see some improved performance (assuming you have a covering index for this query).
WHERE (Cap > '') AND (valueType = '03 - DLP')
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply