Get Totals from a Query

  • Hi

    I have a query that returns all the records that match my criteria.

    However how do I get a count of sub-sets of this result.

    For example....

    I need to the total of all company execs where CON.AccountIdName = 'Company1 Name'

    etc. etc.

    DECLARE @iCompany1Execs INTEGER

    DECLARE @iCompany2Execs INTEGER

    DECLARE @iCompany3Execs INTEGER

    DECLARE @iCompany4Execs INTEGER

    DECLARE @iCompany5Execs INTEGER

    DECLARE @iCompany1TotalINTEGER

    DECLARE @iCompany2TotalINTEGER

    DECLARE @iCompany3TotalINTEGER

    DECLARE @iCompany4TotalINTEGER

    DECLARE @iCompany5TotalINTEGER

    DECLARE@iTotalAllRecsINTEGER

    SELECT

    CON.new_MembershipNumber AS 'Member ID'

    , CON.AccountIdName AS 'Company'

    , STG.Value AS 'Membership Type'

    , CON.FirstName AS 'First Name'

    , CON.LastName AS 'Last Name'

    FROM dbo.Contact CON

    LEFT OUTER JOIN StringMap STG

    ON STG.attributename = 'new_membertype'

    AND STG.attributevalue = CON.new_MemberType

    AND STG.objecttypecode = 2

    AND STG.langid = 1033

    WHERE CON.StatusCode = 1

  • Please provide table create scripts with sample data and expected output and we can write a query to assist. Enable us to help you...

    Best,
    Kevin G. Boles
    SQL Server Consultant
    SQL MVP 2007-2012
    TheSQLGuru on googles mail service

  • Hi

    I sent you the files via pm

  • Why did you send them via PM? Now nobody else gets a chance to answer your question. More eyeballs means better odds at getting more and possible better answers.

    JAT

    __________________________________________________________________________________________________________
    How to Post to get the most: http://www.sqlservercentral.com/articles/Best+Practices/61537/

  • OP is a new user. I already PM'd them back about that. Hopefully they will post up on this thread.

    Best,
    Kevin G. Boles
    SQL Server Consultant
    SQL MVP 2007-2012
    TheSQLGuru on googles mail service

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply