SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Get total of field values


Get total of field values

Author
Message
kaththecoder
kaththecoder
Grasshopper
Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)

Group: General Forum Members
Points: 15 Visits: 23
Hi

I am a newbie and need to get the grand total of the new_TotalNoofPlanMembers field
and am having some difficulty as this isn't working for me.


SELECT
new_MembershipNumber AS 'Membership ID',
FullName AS 'Member Name',
new_SalesChannelOnlyforPrivateMembersName AS 'Bll To Corp. Name',
new_TotalNoofPlanMembers AS 'Total # Plan Members'

sum(new_TotalNoofPlanMembers) as 'Grand Total'


FROM dbo.FilteredContact
Steven Willis
Steven Willis
SSCrazy
SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)

Group: General Forum Members
Points: 2029 Visits: 1721
kaththecoder (7/16/2013)
Hi

I am a newbie and need to get the grand total of the new_TotalNoofPlanMembers field
and am having some difficulty as this isn't working for me.


SELECT
new_MembershipNumber AS 'Membership ID',
FullName AS 'Member Name',
new_SalesChannelOnlyforPrivateMembersName AS 'Bll To Corp. Name',
new_TotalNoofPlanMembers AS 'Total # Plan Members'

sum(new_TotalNoofPlanMembers) as 'Grand Total'


FROM dbo.FilteredContact


Your requirement is a bit vague. So I will assume that the column 'new_TotalNoofPlanMembers' is a previously calculated value. Then in that case I think what you are looking for is COUNT and not SUM (if these are discrete memberships and not money values for instance). Finally, when doing an aggregate such as COUNT or SUM you need to either have a GROUP BY clause or use a windowing function like this:



SELECT
new_MembershipNumber AS 'Membership ID'
,FullName AS 'Member Name'
,new_SalesChannelOnlyforPrivateMembersName AS 'Bll To Corp. Name'
,new_TotalNoofPlanMembers AS 'Total # Plan Members'
,COUNT(new_TotalNoofPlanMembers) OVER (PARTITION BY new_MembershipNumber) AS 'Grand Total'
FROM
dbo.FilteredContact




 
kaththecoder
kaththecoder
Grasshopper
Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)

Group: General Forum Members
Points: 15 Visits: 23
Thanks
I should have been clearer.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search