Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
suresh_dotnet
Starting Member
6 Posts |
Posted - 2009-02-13 : 13:15:57
|
| 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.suresh |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-02-13 : 13:24:38
|
you cant use columns directly in select list unless they're included in group by. so modify like-select OrderFormNo,ClientName,OrderDate,Product,sum(Value),InvoiceQuantity,PendingQuantity from AOM_Tbl_PendingOrders group by OrderFormNo, ClientName,OrderDate,InvoiceQuantity,PendingQuantity |
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-02-13 : 23:35:30
|
| slight modification to visakh codeselect OrderFormNo,ClientName,OrderDate,Product,sum(Value),InvoiceQuantity,PendingQuantity from AOM_Tbl_PendingOrders group by OrderFormNo, ClientName,OrderDate,Product,InvoiceQuantity,PendingQuantity |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-02-14 : 01:01:19
|
| I'm still not sure this wil give you results you want. what according to you must be value returned for sum(Value)? As of now, the query given gives sum of value field for each combination of OrderFormNo, ClientName,OrderDate,Product,InvoiceQuantity,PendingQuantity field values |
 |
|
|
Nageswar9
Aged Yak Warrior
600 Posts |
Posted - 2009-02-14 : 04:38:10
|
| Hi suresh_dotnet,Can u Explain what's ur requirement.... |
 |
|
|
shaihan
Starting Member
20 Posts |
Posted - 2009-02-14 : 09:13:04
|
| your question is not clear. i agree with visakh16 as it gives you a combined sum of value. what are the criteria for calculating the sum? for e.g. if you want to calculate against products ordered by clients then use only clientname and product in group by clause. SELECT ClientName, Product, sum(value)FROM AOM_Tbl_PendingOrdersGROUP BY ClientName, Productthis will give you sum of value for each products ordered by each clients. you can use this query as a inner query and then use join to get other column values.S ]-[ /-\ | ]-[ /-\ N |
 |
|
|
|
|
|
|
|