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
 General SQL Server Forums
 New to SQL Server Programming
 sql sum issue

Author  Topic 

craigmacca
Posting Yak Master

142 Posts

Posted - 2008-01-10 : 15:27:46
Hi i have query which i need to add a sum to but not sure how as i keep getting a ambiguous error!!

i need a sum(cost)as newcost
from this query

SELECT tmp.ID,
tmp.Cost,
tmp.DateofSM,
tmp.MessageText,
tmp.GroupMessageID,
tmp.ClubID,
tmp.RCODE
FROM
(
SELECT t1.ID,
t1.Cost,
t1.DateofSM,
t1.ClubID,
t1.MessageText,
t1.GroupMessageID,
t1.RCODE,
(
SELECT COUNT(*) + 1
FROM SMS_Records
WHERE GroupMessageID=t1.GroupMessageID
AND ID <t1.ID
) AS 'RowNo'
FROM SMS_Records t1
)tmp
WHERE tmp.RowNo=1

AND DATENAME(month, DateOfSM)= @Date
AND ClubID = @ClubID

gavakie
Posting Yak Master

221 Posts

Posted - 2008-01-10 : 15:35:57
you need a group by
Go to Top of Page
   

- Advertisement -