﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / SQL Server 2005 / T-SQL (SS2K5)  / Group by Query Error / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Mon, 20 May 2013 22:56:48 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Group by Query Error</title><link>http://www.sqlservercentral.com/Forums/Topic656860-338-1.aspx</link><description>There is no sense the query you asked for, but it is possible to retrieve the info you need, justbuild your query like the below one:SELECT OrderFormNo	,ClientName	,OrderDate	,Product	,sum(Value)as Total	,InvoiceQuantity	,PendingQuantity FROM AOM_Tbl_PendingOrders GROUP BY OrderFormNo, ClientName,OrderDate, InvoiceQuantity, PendingQuantity, productBut remember there is no sense you get all the fields to sum. You must build a result set  with some sense for example:SELECT ClientName, OrderDate, Sum(value) as TotalFROM AOM_Tbl_PendingOrders Group By ClientName, OrderDateThe above query is gathering All Orders made in a time stamp from customers and applying a sum on value field.It has sense because you can count and know how much you have gain in that time for each Customer.I know it is an old post, but I resolved to explain a little bit more why it had no sense like some folks were talking!Regards </description><pubDate>Wed, 04 Aug 2010 02:36:13 GMT</pubDate><dc:creator>Marcos Leandro Rosa</dc:creator></item><item><title>RE: Group by Query Error</title><link>http://www.sqlservercentral.com/Forums/Topic656860-338-1.aspx</link><description>In group by clause, you should include all the columns present in the select list that are not aggregated.So, in this example include all the columns in the group by clause except Sum(Value).</description><pubDate>Sun, 25 Jul 2010 00:14:34 GMT</pubDate><dc:creator>amrata88</dc:creator></item><item><title>RE: Group by Query Error</title><link>http://www.sqlservercentral.com/Forums/Topic656860-338-1.aspx</link><description>Hi,instead using all the columns in the group by clause, you can use aggregate function "OVER BY " in the query............ORgive me the details of the output what u want.....</description><pubDate>Sat, 24 Jul 2010 09:42:09 GMT</pubDate><dc:creator>VENUGOPAL.RR</dc:creator></item><item><title>RE: Group by Query Error</title><link>http://www.sqlservercentral.com/Forums/Topic656860-338-1.aspx</link><description>What every one else said, and also ...Why are you even trying to use a SUM ... when you're only looking at one row?</description><pubDate>Fri, 13 Feb 2009 13:00:03 GMT</pubDate><dc:creator>bvaljalo-1000038</dc:creator></item><item><title>RE: Group by Query Error</title><link>http://www.sqlservercentral.com/Forums/Topic656860-338-1.aspx</link><description>suresh,Try this: -select OrderFormNo,ClientName,OrderDate,Product,sum(Value),InvoiceQuantity,PendingQuantity from AOM_Tbl_PendingOrders group by OrderFormNo, ClientName,OrderDate,Product,InvoiceQuantity,PendingQuantity In your case, remember that whenever you use the group by clause you need to add all the other colums as well except the function column (i.e. sum)</description><pubDate>Fri, 13 Feb 2009 11:48:55 GMT</pubDate><dc:creator>sam-770000</dc:creator></item><item><title>RE: Group by Query Error</title><link>http://www.sqlservercentral.com/Forums/Topic656860-338-1.aspx</link><description>These error messages are pretty clear. Read the error messages then look at your query.</description><pubDate>Fri, 13 Feb 2009 11:25:37 GMT</pubDate><dc:creator>andrewd.smith</dc:creator></item><item><title>Group by Query Error</title><link>http://www.sqlservercentral.com/Forums/Topic656860-338-1.aspx</link><description>here please refer the table:in that table value:1 is Order No ABCL  is Client Name12/1/2009 12:00:00 AM is OrderDateARMIS - is Product1000 is Value1 is InvoiceQuantity1 is Pendingquantity 1	ABCL	12/1/2009 12:00:00 AM	ARMIS	10000	1	11	HAL	12/1/2009 12:00:00 AM	ARMIS	2000	2	21	NAL	12/1/2009 12:00:00 AM	TimeCheck	20000	2	22	HidusthanLeaver	12/1/2009 12:00:00 AM	ARMIS	2000	2	22	IOC	12/1/2009 12:00:00 AM	TimeCheck	30000	2	23	BEML	12/1/2009 12:00:00 AM	ARMIS	400000	2	23	ABCL	12/1/2009 12:00:00 AM	TimeCheck	500000	3	3 I am using the following Groupby Queryselect OrderFormNo,ClientName,OrderDate,Product,sum(Value),InvoiceQuantity,PendingQuantity from AOM_Tbl_PendingOrders group by OrderFormNo, ClientName,OrderDateI have got the erreor belowMsg 8120, Level 16, State 1, Line 1Column 'AOM_Tbl_PendingOrders.Product' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.Msg 8120, Level 16, State 1, Line 1Column 'AOM_Tbl_PendingOrders.InvoiceQuantity' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.Msg 8120, Level 16, State 1, Line 1Column 'AOM_Tbl_PendingOrders.PendingQuantity' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.Can any one solve this issue.</description><pubDate>Fri, 13 Feb 2009 11:16:51 GMT</pubDate><dc:creator>suresh.s-895438</dc:creator></item></channel></rss>