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 |
kwikwisi
Constraint Violating Yak Guru
283 Posts |
Posted - 2008-06-23 : 22:37:19
|
i can't use sum,why?CREATE PROCEDURE [dbo].[S_GetInfo] @cid intASselect c.Item as item,c.Amount as qty,c.TotalPrice as tprice,m.UnitPrice as uprice,c.GST as gst,sum(c.TotalPrice) as summfrom Tc_Quotation c join Tm_QuotationSubItem mon c.ID=m.IDwhere c.CustomerID=@cidGO |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-06-23 : 22:47:10
|
sum() is an aggregate function. You need to use GROUP BY together with sum().What is your query doing ? KH[spoiler]Time is always against us[/spoiler] |
 |
|
kwikwisi
Constraint Violating Yak Guru
283 Posts |
Posted - 2008-06-23 : 22:51:38
|
I want to sum all of TotalPrice based on CustomerID.quote: Originally posted by khtan sum() is an aggregate function. You need to use GROUP BY together with sum().What is your query doing ? KH[spoiler]Time is always against us[/spoiler]
|
 |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-06-23 : 22:58:22
|
[code]SELECT c.Item AS item, c.Amount AS qty, c.TotalPrice AS tprice, m.UnitPrice AS uprice, c.GST AS gst, s.summFROM Tc_Quotation c INNER JOIN Tm_QuotationSubItem m ON c.ID = m.ID INNER JOIN ( SELECT CustomerID, SUM(c.TotalPrice) AS summ FROM Tc_Quotation GROUP BY CustomerID ) s ON c.CustomerID = s.CustomerIDWHERE c.CustomerID = @cid[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
|
|
|
|