• 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_MembershipNumberAS 'Membership ID',

    FullNameAS 'Member Name',

    new_SalesChannelOnlyforPrivateMembersNameAS 'Bll To Corp. Name',

    new_TotalNoofPlanMembersAS '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