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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 sum??

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 int
AS
select c.Item as item,c.Amount as qty,c.TotalPrice as tprice,m.UnitPrice as uprice,c.GST as gst,sum(c.TotalPrice) as summ
from Tc_Quotation c join Tm_QuotationSubItem m
on c.ID=m.ID
where c.CustomerID=@cid
GO

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]

Go to Top of Page

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]



Go to Top of Page

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.summ
FROM 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.CustomerID
WHERE c.CustomerID = @cid[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -