Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2003
    Posts
    59
    Provided Answers: 1

    Question Unanswered: MS SQL combining COUNT(*) for different tables at once

    Hey all I have a few query's that I would like to combine into ONE query in order to not have to call out to the server multiple times.

    An example of the querys I am using:
    Code:
        SELECT COUNT(*) AS mailCount1 
        FROM [WebContact].[dbo].[memberEmails]  
        WHERE contactdatetime > '01/01/06'
        AND contactdatetime < '02/01/06'
    
        SELECT COUNT(*) AS mailCount2
        FROM [WebContact].[dbo].[otherEmails]
        WHERE contactdatetime > '01/01/06'
        AND contactdatetime < '02/01/06'
    
        SELECT COUNT(*) AS mailCount3 
        FROM [WebContact].[dbo].[memberEmails]  
        WHERE contactdatetime > '02/01/06'
        AND contactdatetime < '03/01/06'
    
        SELECT COUNT(*) AS mailCount4
        FROM [WebContact].[dbo].[otherEmails]
        WHERE contactdatetime > '02/01/06'
        AND contactdatetime < '03/01/06'
    
        etc etc...
    So as the examples above, only thing that changes are:

    > The FROM (memberEmails & otherEmails)

    > The > & < months (01/01/06, 02/01/06 | 02/01/06, 03/01/06 | etc...)

    Is this possible to do within one query?

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Quote Originally Posted by StealthRT View Post
    Is this possible to do within one query?
    Yes, you can.

    The exact syntax depends on what:
    Quote Originally Posted by StealthRT View Post
    etc etc....
    includes.

    -PatP
    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •