Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Get total of field values Expand / Collapse
Author
Message
Posted Tuesday, July 16, 2013 3:50 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, March 06, 2014 7:10 AM
Points: 9, Visits: 13
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

Post #1474319
Posted Tuesday, July 16, 2013 4:16 PM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Sunday, September 29, 2013 1:24 AM
Points: 429, Visits: 1,721
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


 
Post #1474329
Posted Tuesday, July 16, 2013 5:02 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, March 06, 2014 7:10 AM
Points: 9, Visits: 13
Thanks
I should have been clearer.
Post #1474339
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse