Results 1 to 3 of 3

Thread: [RESOLVED] SQL 2000 SELECT/Count ?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2006
    Posts
    93

    Resolved [RESOLVED] SQL 2000 SELECT/Count ?

    I am using SQL Server 2000. I have a field in table one that stores values, in this case 35 thru 46. I am tyring to count each of those values in table two. I can write the count statement easy enough to give me what I expect to see. EValue are the values stored in table one and count is the count of each value in table two:

    EValue CountofResponse
    38 65
    42 4
    43 1
    44 6
    45 18
    46 20

    This is what I would like to see:

    EValue CountofResponse
    35 0
    36 0
    37 0
    38 65
    39 0
    40 0
    41 0
    42 4
    43 1
    44 6
    45 18
    46 20

    Here is the SQL I am using now:
    SELECT dbo_tblMDD.EValue, Count(dbo_tblData.Response) AS CountOfResponse
    FROM dbo_tblMDD INNER JOIN dbo_tblData ON (dbo_tblMDD.EValue = dbo_tblData.Response) AND (dbo_tblMDD.VID = dbo_tblData.VID) AND (dbo_tblMDD.PID = dbo_tblData.PID)
    GROUP BY dbo_tblMDD.VID, dbo_tblMDD.PID, dbo_tblMDD.EValue
    HAVING (((dbo_tblMDD.VID)=47) AND ((dbo_tblMDD.PID)="340109"))
    ORDER BY dbo_tblMDD.EValue;


    Thanks for you help in advance!!

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: SQL 2000 SELECT/Count ?

    change your inner join to an outter join.... change your having to a WHERE and move it up to before the Group By.... change the COUNT to the following:

    SUM(CASE
    WHEN dbo_tblData.Response IS NOT NULL THEN 1
    ELSE 0
    END )

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Aug 2006
    Posts
    93

    Re: SQL 2000 SELECT/Count ?

    Worked like a charm!!

    Thanks techgnome

Posting Permissions

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



Click Here to Expand Forum to Full Width